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

1 Answer 1

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();
}
1
  • Its not working
    – JageshMk
    Commented Jan 29, 2015 at 12:37

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.