Magento get bestseller from category
Magento get bestseller from category
Magento already uses bestseller products aggregation that can be checked under Admin > Reports > Products > Bestsellers. Thanks to this aggregated data we no longer need to determine the total of all the orders to see which products are sold the most. By the variety of aggregation data we’re able to get the most popular products not only from the beginning, but for each specific day, month or year
<?php $productCount = 10; //insert how much prodect $storeId = Mage::app()->getStore()->getId(); $collection = Mage::getResourceModel('reports/product_collection') ->addAttributeToSelect('*') ->addOrderedQty() ->setStoreId($storeId) ->addStoreFilter($storeId) ->addCategoryFilter(Mage::registry('current_category')) ->setOrder('ordered_qty', 'desc') ->setPageSize($productCount); Mage::getSingleton('catalog/product_status') ->addVisibleFilterToCollection($collection); Mage::getSingleton('catalog/product_visibility') ->addVisibleInCatalogFilterToCollection($collection); ?>