Magento – recently viewed products not showing for guest users

loggingmagento-1.9productsuser

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()):
    $i=0;
    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>'; 
    endforeach;
endif;

Best Answer

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 '';
} */

$this->setDisplayMinimalPrice('1');
$collection = $this->_getRecentProductsCollection();

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

return parent::_toHtml();
}
Related Topic