How To: Add Attributes to Product Grid in Category

Introduction

Here we will show how to add your more attributes to the category view product list or grid.


Update catalog/product_list block

NOTE: Since v0.9 this method is already implemented

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:

//...
  /**
   * 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;
  }

Do same thing for <catalog_category_layered>


Update templates

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

<!-- ... -->
<?php foreach ($_productCollection as $_product):?>
<!-- ... -->
<!-- these are regular text attributes -->
  <?php echo $_product->getMyAttribute()?><br />
  <?php echo $_product->getAnotherCustomAttribute()?>
 
<!-- this is dropdown attribute -->
  <?php echo $_product->getAttributeText('your_attribute')?>
<!-- ... -->
<?php endforeach?>
<!-- ... -->


  • Email, SSL
  • 16 Users Found This Useful
Was this answer helpful?

Related Articles

How To: Upgrade Magento to the Latest Version

Note: It is always recommended to perform multiple form of backups before you perform any...

How To: Display Products on Homepage

There are numerous ways to put products on your home page, and we’ll compile a list of code...

How To: Install Magento using Installatron Script Installer

There are a few easy steps that you will need to take to install Magento using Installatron...

How To: Improve Magento Performance

Important Note: The following tips on performance improvements have been tested to work properly...

How To: Setup Multiple Store for Magento

The following is the recommended guide to setup a Magento Multi-Store on our hosting plans. A...