Thursday 25 April 2013

Magento Most popular products for each category


<?php $get_cat = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();

$category = Mage::getModel('catalog/category')->load($get_cat);
$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);

foreach ($products as $prod){

 if($prod->getIsActive()){
echo $this->htmlEscape($prod->getName());
echo "<br>";
 }

}

?>

No comments:

Post a Comment