Displaying custom attributes on product view pages

On a product view page product attributes are displayed by default in a specific location – but what if you want to display these attributes elsewhere on product view pages? This can easily be achieved with the below snippets.

For drop down attributes

For all other attributes

Displaying custom attributes on other templates

In order to display custom attributes on other pages we need to modify the way the product collections are loaded. Magento does provide a back-office ‘used in product listings’ setting to allow the attributes to be displayed on standard listing pages, such as category pages but for the purpose of this example we will look at adding them to other pages.

We need to modify 2 functions, which are used for loading the product collections:

  • public function getItemCollection()
  • public function getProductCollection()

To load a custom attribute you need to modify the above functions to.include a addAttributeToSelect(‘custom_attribute’) function call to load our custom attributes.

For this example lets add a custom attribute to app/code/core/Mage/Catalog/Helper/Product/Compare.php and change:

This will then allow us to use that custom attribute, like so:

Leave a Reply