Oct 18, 2012
kalpesh

Magento Get most popular products in a category

Magento get most popular products in any specified category using below code, you can show them in the sidebar of product detail page to let your visitors know the popularity of the products for that category.

$category = Mage::getModel('catalog/category')->load($categoryId); 
$products = Mage::getResourceModel('reports/product_collection') 
    ->addOrderedQty() //total number of quantities ordered
    ->addAttributeToSelect('*') //get all attributes
    ->setOrder('ordered_qty', 'desc') //most ordered quantity products first
    ->addCategoryFilter($category);

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions