1

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;
  • Can you please paste your recently view product block code here ? – Siddharth Vaghasia Jan 23 '15 at 7:22
  • {{block type="reports/product_viewed" template="reports/product_viewed.phtml"}} – JageshMk Jan 23 '15 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 ? – Siddharth Vaghasia Jan 23 '15 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 '15 at 9:53
  • edit your question and paste it as code, this does not displays right. – Siddharth Vaghasia Jan 29 '15 at 10:03
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 '';
} */

$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();
}
| improve this answer | |
  • Its not working – JageshMk Jan 29 '15 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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