Sunday, July 8, 2012

How to get Most Viewed products in Magento?

$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_r($products);

No comments:

Post a Comment

Please mention your comments.......