Display Most Viewed Products In Magneto

One of my client wants his visitor to see most viewed item on product detail page “view.phtml”, so i found following solution,
it will return array of product just use this array to display most view products.
[php]
<?php
$productCount = 5;

$storeId = Mage::app()->getStore()->getId();

$products = Mage::getResourceModel(‘reports/product_collection’)
->addAttributeToSelect(‘*’)
->setStoreId($storeId)
->addStoreFilter($storeId)
->addViewsCount()
->setPageSize($productCount);

Mage::getSingleton(‘catalog/product_status’)
->addVisibleFilterToCollection($products);
Mage::getSingleton(‘catalog/product_visibility’)
->addVisibleInCatalogFilterToCollection($products);

print"<pre>";
print_r($products);
?>
[/php]
note:- the above code will only return array of most viewed products, just manupilate array in your design.

Leave a Comment

Your email address will not be published. Required fields are marked *

*