here is the code:
public function getMostViewedProducts() { /** * Number of products to display * You may change it to your desired value */ $productCount = 5; /** * Get Store ID */ $storeId = Mage::app()->getStore()->getId(); /** * Get most viewed product collection */ $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); return $products; }
Hope it Helps! Thanks..
No comments:
Post a Comment