Magento: Display Most Viewed Products

Here, I will show you the code to get the most viewed products in Magento. It will return array of product just use this array to display most view products.

<?php 
$productCount = 5; 
$storeId = Mage::app()->getStore()->getId(); 
$products = Mage::getResourceModel('reports/product_collection')
           ->addAttributeToSelect('*') 
           ->setStoreId($storeId) 
           ->addStoreFilter($storeId) 
           ->addViewsCount()
           ->setPageSize($productCount); 

print"<pre>"; 
print_r($products); 
print"</pre>";
?>

Note:- The above code will only return array of most viewed products, just manipulate array in your design.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s