Show recent_viewed products on product Page

10,138

Solution 1

In your theme you will modify the catalog.xml file (/app/design/frontend/{your theme}/default/layout/catalog.xml). Find the following section and add a block call for the template towards the bottom of the content reference.

<catalog_product_view translate="label">
 <reference name="content">
  <block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/>
 </reference>
</catalog_product_view>

Then you need to modify your theme for where you want the block to show up. In /app/design/frontend/{your theme}/default/template/catalog/product/view.phtml add the following line where you want the Recently Viewed products to show up.

<?php echo $this->getChildHtml('product_recently_viewed') ?>

That will get it to show but you may need to tweak the template a bit because it is designed for the left column and may not layout properly if you insert it into the middle one.

Solution 2

Show recently viewed product anywhere with this code.

echo $this->getLayout()->createBlock("reports/product_viewed")->setTemplate("reports/product_viewed.phtml")->toHtml();

Solution 3

You have two options. You can use layout XML to make the right.reports.product.viewed block a child of the product.info block and a getChildHtml() call to the catalog/product/view.phtml template, or you can change the product page to a 2column-right layout.

Share:
10,138
ScoRpion
Author by

ScoRpion

I Work On PHP Symfony2 Magento Zend Fusebox Python OpenERP JavaScript JQuery Ajax ( JQuery And Prototype ) And I am passionate about sketching my new ideas into programming Applications.

Updated on June 04, 2022

Comments

  • ScoRpion
    ScoRpion almost 2 years

    The Current default functionality of magento is that it shows the recently viewed products on right side of category page. Now I would like to display the same content on at the bottom of product page. the phtml file used is named at location as

    frontend/base/default/template/reports/product_viewed.phtml.

    Is there any simple way to do it ?

  • ScoRpion
    ScoRpion over 12 years
    magento Comes with default layout for product page, Even if its a 3 column It wont be available in product page.. well it can be found on category page
  • ScoRpion
    ScoRpion over 12 years
    :- It Is Not Working At All... even I tried to use exit; after the above line in view.phtml.. Not Working ...
  • benmarks
    benmarks over 12 years
    "default layout" is a function of the "root" declaration in page.xml. Any layout file can change that via layout update handle ("default" is loaded first). In your local.xml you can use the `<catalog_product_view> handle to update the root node with a reference.
  • Greg Demetrick
    Greg Demetrick over 12 years
    Sorry, I was missing an "as" caluse int eh instructions. I have updated them and tested it on my local install to confirm this works. Also, keep in mind that this zone will be suppressed until you go to two different products and you actually have recently viewed items. I just ran into that issue.
  • ScoRpion
    ScoRpion over 12 years
    Thanks A lot Dear.. it worked instantly.. I will feel happy if u can explain the process how it worked.. what exactly is happening.. Thanks once again..
  • Greg Demetrick
    Greg Demetrick over 12 years
    The best way to think of this is that the products_viewed.phtml file is a template or object for the content you want. To use this on the Product page you have to tell the catalog class which contains product pages where the template/object is then on the display page you have to tell it where the object should go. The addition to the catalog.xml page tells the catalog class where the template is & where it can be used. In this case that is only on Product pages. The change to the view.phtml file tells the page to pull the template object and place it on the display at that location.