How can I get custom attributes in the Magento (version 1.4) category list of products (in list.phtml
)?
I am trying to edit catalog.xml
by adding
<action method="addAttribute"><code>format</code></action>
and开发者_Go百科 in list.phtml
<?php echo $_product->getAttributeText('format'); ?>
or
<?php echo $_product->getFormat(); ?>
But it doesn't work. How can this be done?
It works fine, just place this code to where you need in list.phtml or view.phtml file.
$attribute = $_product->getResource()->getAttribute('unit');
if ($attribute){
echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}
Load attributes via $_product->getAttributes()
http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Model_Product.html#getAttributes
精彩评论