How to add attributes to product grid in category

Last modified by Moshe on Thu, June 24, 2010 16:40
Source|Old Revisions  

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:

  1. //...
  2.   /**
  3.    * Use this method in layouts for extra attributes
  4.    *
  5.    * @param string $code internal name of attribute
  6.    */
  7.   public function addAttribute($code)
  8.   {
  9.     $this->_getProductCollection()->addAttributeToSelect($code);
  10.     return $this;
  11.   }

This method will be included in future releases.

Update layout XML

Update layouts where needed, add your custom attributes you need to show:

  1. <layout>
  2. <!-- ... -->
  3.   <catalog_category_default>
  4. <!-- ... -->
  5.       <block type="catalog/product_list" name="product_list">
  6. <!-- START UPDATE -->
  7.         <action method="addAttribute"><attribute>my_attribute</attribute></action>
  8.         <action method="addAttribute"><attribute>another_custom_attribute</attribute></action>
  9. <!-- END UPDATE -->
  10.       </block>
  11. <!-- ... -->
  12.   </catalog_category_default>
  13. <!-- ... -->
  14. </layout>

Do same thing for <catalog_category_layered>

Update templates

app/design/frontend/default/default/template/catalog/product/list.phtml:

  1. <!-- ... -->
  2. <?foreach ($_productCollection as $_product):?>
  3. <!-- ... -->
  4.   <?=$_product->getMyAttribute()?><br />
  5.   <?=$_product->getAnotherCustomAttribute()?>
  6. <!-- ... -->
  7. <?endforeach?>
  8. <!-- ... -->



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs