tags:

views:

643

answers:

3

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!

A: 

(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);
Laizer
the link works for me
a1anm
works for me now
Laizer
A: 

hi, for the best selling product on homepage please visit this one http://inchoo.net/ecommerce/magento/bestseller-products-in-magento/

Muzafar Ali
A: 

Works well, but is that possible to get grouped product treaded as simple products...so idea is, when i buy grouped product, in final report I got updated sell quantity for simple products, not grouped one =) Thanks for response!

Elvis