Output a Static Block on the Product Description - magento

I wish to add a Static Block(s) to Magento's product description field in the same way it could be added to a regular page. Example: http://www.screencast.com/t/l5DbjRZagVKv
If I add the code: {{block type="cms/block" block_id="your_block_id"}} to the page description of a product it will just output as text. Example: http://www.screencast.com/t/pUS4CObZ
It is important that I am able to manage static blocks for a range of similar products, for example Electral goods have different Warranty information than Bathroom products. The information will be the same across 100s of products but not all of them.
If there is a solution/workaround that someone could suggest then it would be greatly appreciated. I've been googling all day and their seems to be nothing.
Many thanks in advance!

I may not be sure what you want to achieve but according to my understanding i think you want to show the static block to some limited number of products.Is it right?If so than you can create a new category and assign those products to that category.
Now all you need to do is go to your "app/design/frontend/base/default/template/catalog/product/view.phtml".
Here you need to check the condition that if the product is of the particular category you defined than you output that block.
To output the static block in the template file you can do following.
echo $this->getLayout()->createBlock('cms/block')->setBlockId('my-new-block')->toHtml();
Hope you understood what i am trying to say and hope it will help.

Related

Interpreting where I would find the output files in Magento - templates

I am a few weeks into using Magento, and this is a URL for which I'm trying to track the output file (I believe it would be a .phtml file):
http://mytest.shopland.com/smi130495/catalog/category/view/s/his-jewelry/id/312834/
the first parameter smi130495 is the store parameter, and obviously the last two are a name-value pair for the category. I'm pretty sure we have NOT touched core, so there might be files in local. However I'm also aware that there is a skin folder. Does anyone have a suggestion of how to interpret it? Thanks.
It would probably help you a lot to read an article about how Magento routing works, but I will explain briefly what your URL means:
smi130495: As you stated, this is your store code. Since Magento can support multiple tiers of websites/stores, this is an optional piece that depends on your setup.
catalog/category/view: This is the routing information (module, controller, action). This gets translated into a dispatch of Mage_Catalog_CategoryController::viewAction() found in the file app/code/core/Catalog/controllers/CategoryController.php.
s/his-jewelry: You are correct that this is where the params begin. This looks like a search term being passed from search results.
id/312834: This is the category ID that will be loaded by the dispatched controller action.
Knowing this information is the first clue to finding the code that will be used to create your output, but there is much more that goes into the rendering of the final output. It would be too long to explain everything here that can impact output since, for example, Magento uses an intermediate XML-based layout layer of “blocks” that in turn make use of templates to render specific pieces of content on the page.
However, I can point you to the main template for your route app/design/frontend/$package/$theme/template/catalog/category/view.phtml, which gets added to the layout like this in app/design/frontend/$package/$theme/layout/catalog.xml:
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
</reference>
Hope that helps you some.
In Magento .phtml files are inside :
Admin panel files : app/design/adminhtml/default/default/template
Frontend files : /app/design/frontend/default/{theme name}/template
Like in query you are searching for category/view file
app/design/frontend/default/{theme name}/template/catalog/category/view.phtml
To make life easier, you can use several tools. Finding Templates in Magento sometimes is alot of work. Template Hints are a good way to find templates quicker. You can enable template-hints in the Magento backend in the Configuration under System->Development. In case you want a better solution with template hints, you can use this module from AOE:
https://github.com/AOEpeople/Aoe_TemplateHints
Hope this helps, regard, David

Magento - Get attribute options value and quantity

Hello and good day to all the members of this great community. I'm still new in PHP and especially in Magento.
I'm not posting, waiting for answers, and leaving without replying back. This is a learning process. I hope to get a great support from all of you.
I have a product. I did create custom option for the product, that is an attribute named "a_size". The attribute has value of S, M and L. Each of the value has quantity.
In the single product view, I would like to call all the available size. That is the size (S, M, or L) that has quantity more than 0. I just want to show the available size, not how much the size left.
Can anybody guide me? I'm using Magento 1.7.x and as far for this 2 weeks, I did try pretty many of suggested answers from the community thru the search function.
The replies will be much appreciated. Thank you.
There are a few things to try.
Firstly check that when you set up your new attribute in the Magento Admin (Catalog->Attributes->Manage Attribute) that in the Frontend Properties box you have set Visible on Product View Page on Front-end to yes.
To get size values I use this code:
$cabac_sizeAttribute = $_product->getAttributeText("a_size");
but I have other code for getting attribute values that goes like this:
$_product_helper = Mage::helper('catalog/output');
$temp = $_product_helper->productAttribute($_product, $_product->getASize(), 'a_size');
I think it is related to the type of attribute: text, dropdown, multiselect etc so try both and see how you get on. But really the function productAttribute() is just applying formatting. You can read the function in the file app/core/Mage/Catalog/Helper/Output.php
Also, I wonder, if you have set up a configurable product and you are on the product view page then you will be viewing the configurable product. That product won't have an a_size value: you are trying to access the a_size attribute of the simple products that make up the configurable product, yes? Everything I wrote above is (I think) correct but to get the attribute of the simple products that are part of a configured product you should study the code in the function getJsonConfig() of the file app/core/Mage/Catalog/Block/Product/View/Type/Configurable.php
And in particular to these lines:
//file: file app/core/Mage/Catalog/Block/Product/View/Type/Configurable.php
//class: Mage_Catalog_Block_Product_View_Type_Configurable
//function: getJsonConfig()
foreach ($this->getAllowProducts() as $product) {
$productId = $product->getId();
foreach ($this->getAllowAttributes() as $attribute) {
$productAttribute = $attribute->getProductAttribute();
$productAttributeId = $productAttribute->getId();
$attributeValue = $product->getData($productAttribute->getAttributeCode());
Being careful about variable naming: $product is local here, I suggest changing it, and about $this - but if you are in a .phtml of the product view for configurables then I think your $this is already Mage_Catalog_Block_Product_View_Type_Configurable
Welcome to Magento coding. You are doing well; it is a long but rewarding path. (hints: local.xml is your vital friend and so is Alan Storm if you haven't come across his content yet.)
[Additionally, (welcome to Magento) I think you are trying to say eg S and L are out of stock and M is in stock but actually the function getAllowProducts() will disallow a product with zero stock and exclude it from the returned object. You will need to use
$allProducts = $this->getProduct()->getTypeInstance(true)
->getUsedProducts(null, $this->getProduct());
(taken from function getAllowProducts() in file app/core/Mage/Catalog/Block/Product/View/Type/Configurable.php)
and then, if needed, check that each product is allowed to be shown eg status=ENABLED, and then check its stock level...
]
Malachy.
If you want to get the values of your drop down attribute use the following code
$_product->getASize();
and initially load the product object

Add character to Magento price

this is for Magento. I would like to add an * to all the prices on the product listing page. I've already done some of them, but would like to know where I can add this specifically to bundle, 'to' and 'from' prices. I have looked under app/design/frontend/base/default/template/bundle/catalog/product/price.phtml and found the price-from and price-to classes. I don't know where in this block I can add the asterisk to the price. I would like to add some code, but it does not want to display everything correctly when trying to post it. Thanks
Its a bit tricky to output different price formats for different product types. But since you have found the CSS classes, why not do it with some JS?
$$('.price-from > .price').each(function(element){ element.insert({after: '*'})});

Magento: how to get the price of a product with catalog rules applied

I'm developing a script (external to Magento, not a module) which aims to output a text list of all available products, their prices and some other attributes. However, catalog price rules don't seem to be applied to product prices. If I use any of the following:
$_product->getPrice()
$_product->getFinalPrice()
I get the normal price (without rules being applied).
If I use:
$_product->getSpecialPrice()
I get null unless the product actually has a special price inserted in the product itself (i.e. if special price is not related with catalog rules).
I also tried
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice())
as suggested in the answer given by Fabian Blechschmidt, but interestingly it returns the normal price only if the product is affected by any catalog rule, returning null otherwise.
There was a similar question in StackOverflow and Magento Forums some time ago, but the provided answer (which is to insert the code bellow) doesn't work for me (returned prices remain the same).
Mage::app()->loadAreaPart(Mage_Core_Model_App_Area::AREA_FRONTEND,Mage_Core_Model_App_Area::PART_EVENTS);
Does anybody have an idea of how to achieve this?
I'm using Magento 1.6.2.0.
Thanks in advance.
Thanks to you, I found a new site:
http://www.catgento.com/magento-useful-functions-cheatsheet/
And they mentioned:
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice())
HTH
As catalog price rules heavily depend on time, store and visiting customer, you need to set those parameters when you want to retrieve the product final price with it's price rules applied.
So, in your case, make sure that provided product is passed with the desired store and customer group id, which can be set as:
Mage::getModel('catalogrule/rule')->calcProductPriceRule($product->setStoreId('STORE_ID')->setCustomerGroupId('CUSTOMER_GROUP_ID'),$product->getPrice())
I discovered the problem. The discounted prices display Ok in the store frontend. The problem was that I was developing a script "external" to Magento (thus not a Magento module), something like:
<?php
set_time_limit(0);
ignore_user_abort();
error_reporting(E_ALL^E_NOTICE);
header("Content-Type: text/plain; charset=utf-8");
require_once "app/Mage.php";
// Get default store code
$default_store = Mage::app()->getStore();
...
For everything to work properly it seems that one must follow the proper Magento bootstrap, and develop everything as a module. My script was so simple that I thought it wouldn't be necessary to code a complete module. In other words, everything in Magento should really be a module.
Concluding, using the module approach, all the methods work as expected:
$_product->getPrice()
$_product->getFinalPrice()
$_product->getSpecialPrice()
Thank you all for your input.
This helped me in this issue: http://www.magentocommerce.com/boards/viewthread/176883/
. Jernej's solution seems plausible, but it does not handle rules that Overwrite other rules by using 'stop processing' and therefore can apply more than one rule.
$original_price = $_product->getPrice();
$store_id = 1; // Use the default store
$discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
Mage::app()->getLocale()->storeTimeStamp($store_id),
Mage::app()->getStore($store_id)->getWebsiteId(),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
$_product->getId());
// if the product isn't discounted then default back to the original price
if ($discounted_price===false) {
$discounted_price=$original_price;
}

How to prevent ordering certain products - or a category - from a specific country

I have a category dedicated for exported goods , obviously , they will not be sold locally . so , how can I prevent customers who are from my country from ordering products that are meant only for exporting.. and showing an error message .. please help !
I would say that you will have to create a new product type. You'll need a new module (use Daniel's excellent kick-start extension: http://www.magentocommerce.com/magento-connect/Daniel+Nitz/extension/1108/modulecreator) and then have your model extend Mage_Catalog_Model_Product_Type_Simple.
Then, add a new attribute for your new product type to capture Allowed Countries, and implement the isSalable method in your Model to check for Allowed Countries.
This is not trivial, but it should be the right approach. The guys at Inchoo (who write a great blog) have a good tutorial on the process: link text and in fact they've provided the shell of the module.
Good luck!
JD

Resources