Recently viewed products not showing for guest users. but its working fine for loggedin users. How to show Recently viewed products for guest users? Where to customize the code?

I am displaying recently viewed product in home page and product details page.

(edit from OP):

phtml code :

if (($_products = $this->getRecentlyViewedProducts()) && $_products->getSize()):
    foreach ($_products->getItems() as $_product):
        echo '<a href="'.$_product->getProductUrl().'" title="'. $this->htmlEscape($_product->getName()).'">'; 
        echo '<span class="product-name">'.$_product->getName().'</span>'; 
        echo '<span>'. Mage::helper('core')->currency($_product->getFinalPrice(),true,false).'</span>';
        echo '</a>'; 
  • Can you please paste your recently view product block code here ? Jan 23, 2015 at 7:22
  • {{block type="reports/product_viewed" template="reports/product_viewed.phtml"}}
    – JageshMk
    Jan 23, 2015 at 8:50
  • I might have not asked right question...send your phtml code...and where are you displaying recently viewed product on product detail page ? Jan 23, 2015 at 9:37
  • I am displaying recently viewed product in home page and product details page. phtml code : <?php if (($_products = $this->getRecentlyViewedProducts()) && $_products->getSize()): ?> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"> <span class="product-name"><?php echo $_product->getName() ?></span> <span><?php echo Mage::helper('core')->currency($_product->getFinalPrice(),true,false); ?></span> </a> <?php endforeach; ?> <?php endif; ?>
    – JageshMk
    Jan 29, 2015 at 9:53
  • edit your question and paste it as code, this does not displays right. Jan 29, 2015 at 10:03

1 Answer 1


You could try this solution from: https://stackoverflow.com/questions/15682483/how-to-get-recently-view-product-for-guest-user-in-magento

Override: class Mage_Reports_Block_Product_Viewed

Add this function:

   protected function _toHtml() {

/*   if ($this->_hasViewedProductsBefore() === false) {
    return '';
} */

$collection = $this->_getRecentProductsCollection();

$hasProducts = (bool)count($collection);
//        if (is_null($this->_hasViewedProductsBefore())) {
//           Mage::getSingleton('reports/session')->setData('viewed_products', $hasProducts);
//        }
if ($hasProducts) {

return parent::_toHtml();
  • Its not working
    – JageshMk
    Jan 29, 2015 at 12:37

Your Answer

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

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