How to add attributes to product grid in category
This is an old revision of the document!
Introduction |
Here we will show how to add your more attributes to the category view product list or grid.
Update catalog/product_list block |
Add this method to Mage_Catalog_Block_Product_List: app/code/core/Mage/Catalog/Block/Product/List.php:
- //...
- /**
- * Use this method in layouts for extra attributes
- *
- * @param string $code internal name of attribute
- */
- public function addAttribute($code)
- {
- $this->_getProductCollection()->addAttributeToSelect($code);
- return $this;
- }
This method will be included in future releases.
Update layout XML |
Update layouts where needed, add your custom attributes you need to show:
- <layout>
- <!-- ... -->
- <catalog_category_default>
- <!-- ... -->
- <block type="catalog/product_list" name="product_list">
- <action method="addAttribute"><attribute>my_attribute</attribute></action>
- </block>
- <!-- ... -->
- </catalog_category_default>
- <!-- ... -->
- </layout>
Do same thing for <catalog_category_layered>
Update templates |
app/design/frontend/default/default/template/catalog/product/list.phtml:
- <!-- ... -->
- <?foreach ($_productCollection as $_product):?>
- <!-- ... -->
- <?=$_product->getMyAttribute()?>
- <!-- ... -->
- <?endforeach?>
- <!-- ... -->


