0

I added "Recently viewed products" to the bottom of the product view page by adding this code in to local.xml file:

<!-- Showing Recently Viewed Products on Product View Page -->
<catalog_product_view translate="label">    
    <reference name="content">         
        <block type="reports/product_viewed" name="right.reports.product.viewed" as="recently_viewed" template="reports/product_viewed.phtml" />     
    </reference> 
</catalog_product_view>

It works great, however the container for the recently viewed product is always showing even if there are no recently viewed products.

How can I add a condition to the above code in local.xml so that the "Recently viewed product" should show only if any recentley viewed product exist?

Thanks

2 Answers 2

1

The default template reports/product_viewed.phtml already does this:

<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
<div class="block block-list block-viewed">
    ....
</div>
<?php endif; ?>

If there are no recently viewd products, $this->getRecentlyViewedProducts() returns null and nothing is displayed.

Probably your theme has its own product_viewed.phtml template, please make sure, it contains this condition as well.

0

Homtom,please change

Check reference name may be product.info instead of content if want to show at view.phtml

At catalog/product/view.phtml you need to call this by callling html

<?php echo $this->getChildHtml('recently_viewed');?>
1
  • Thanks for your solution. But if I change the code as you have suggested, then "Recently viewed products" dosent show at all!! Any idea why?
    – HomTom
    Commented Nov 18, 2014 at 18:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.