Display Related products on product details page in Magento

June 2nd, 2012 by Laeeq | 2 comments

As a magento developer, many times we had requirement to display related product on product details page. Actually it’s very easy to show related product by following few easy steps. First we will have to add products to a particular product as related product.

Screen shows product added as related product

Follow the below steps to display related products.

1. Open catalog.xml, found in

app/design/frontend/default/YOURTEMPLATE/layout/

2. In catalog.xml find the catalog_product_view section, around line 220. In the section, remove or comment out:
  1. <block type=“catalog/product_list_related” name=“catalog.product.related” before=“-” template=“catalog/product/list/related.phtml”/>

and replace with:

  1. <reference name=“content”>
  2. <block type=“catalog/product_view” name=“product.info” template=“catalog/product/view.phtml”>
  3. <block type=“catalog/product_list_related” name=“catalog.product.related” as=“related” template=“catalog/product/list/related.phtml”/>
  4. </block>
  5. </reference>

3. Now in your catalog/product/view.phtml you can print out the related products using
  1. <?php echo $this->getChildHtml(‘related’); ?>

To edit the look of that list, edit catalog/product/list/related.phtml

OR You can also try this code to display related products
  1. <?php echo $this->getChildHtml(‘catalog.product.related’) ?>

If that above code doesn’t work, you might also try:

  1. <?php echo $this->getLayout()->getBlock(‘catalog.product.related’)->toHtml()?>

 

Hope it will work for you!

You can subscribe to PHPZAG.COM posts by Email

 

Related Topics:

  • Get an array of billing addresses and shipping addresses in Magento
  • Duplicate Data Issue with Custom Magento Collection
  • Tips To Improve Your Ecommerce Site’s Security
  • Magento: Display New Products from Specific Category On Home Page
  • Dealing with Magento Model or Collections
  • Magento: Display New Products On Home Page
  • Magento: Display More Than 5 New Products
  • Override Controllers in Magento
  • Improve the performance of your Magento store
  • Magento Released Community Edition 1.7.0.1
  • Write custom title, keywords and description in Magento module
  • Moving Magento site from development to live server
  • Magento – Models, resource models, and collections
  • Magento – Add thumbnail images to Magento admin grid
  • Simple url rewrite in magento
  • Generate CSV file in Magento
  • Resize image in Magento using Varien_Image class
  • AJAX requests in Magento
  • Category Navigation Listings in Magento
  • Magento- Create a Drop-Down of Countries
  •  

     

    1. June 4th, 2012 at 01:13 | #1

      obviously like http://www.phpzag.com however you need to test the spelling on several of your posts. A number of them are rife with spelling problems and I to find it very troublesome to tell the reality nevertheless I’ll definitely come back again.

    2. June 13th, 2012 at 18:00 | #2

      Very interesting information!Perfect just what I was looking for!

    1. No trackbacks yet.