Magento get Most Viewed Products


Magento get Most Viewed Products : You can get most viewed products from the resource model reports/product_collection. Using this model you can get the product ids which has been viewed most among the all products. Using the product ids you can load other details of the product using the catalog product model. Here we are going to explain the simple collection to get most viewed products in magento.


Magento get Most Viewed Products

Mage::getResourceModel(‘reports/product_collection’)->addViewsCount() Collection is used to get the most viewed items. Here is example to get the ids of these products-

Magento get Most Viewed Products:

$mostViewedProd = Mage::getResourceModel('reports/product_collection')
              ->addViewsCount() 
			  ->setPageSize(10);
$productIds = array();

foreach ($mostViewedProd as $product) {
   $productIds[] = $product->getId();
}

You can set the page size and other filters you want. The above example will give you top 10 most viewed products. For more details you can load product details using Mage::getModel(‘catalog/product’). and ids of products


Advertisements

Add Comment

📖 Read More