Magento Store - Best Selling items by Category [closed]
I'm using this code to create a list of best selling items in Magento:
http://bit.ly/6rzMXf
Does anyone know how this could be edited so it would show best selling items from a specific category?
Thanks!
(Link was dead. Seems to work now.)
I'm not an expert, yet, but I believe you want to add a filter to the product collection.
In the line:
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId);
You want to add a filter for category. I'm assuming you're looking for a static category here, and not something dynamic from context or user input. The code below replaces the above - load the category object from the category number, then apply the filter. I think it should work.
$catNum = 7; //The number of the category you want to load
$category = Mage::getModel('catalog/category')->load($catNum);
$products = Mage::getResourceModel('reports/product_collection')
->addOrderedQty()
->addAttributeToSelect('*')
->setStoreId($storeId)
->addStoreFilter($storeId)
->addCategoryFilter($category);
for the best selling product on homepage please visit this one http://inchoo.net/ecommerce/magento/bestseller-products-in-magento/
精彩评论