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!


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.   }

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.         <action method="addAttribute"><attribute>my_attribute</attribute></action>
  7.       </block>
  8. <!-- ... -->
  9.   </catalog_category_default>
  10. <!-- ... -->
  11. </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()?>
  5. <!-- ... -->
  6. <?endforeach?>
  7. <!-- ... -->



 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs