开发者

Magento Store - Best Selling items by Category [closed]

开发者_Go百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜