NewUser
NewUser

Reputation: 13333

magento show number of products in the category?

I am pretty newbie to the magento. I want to show the number of products in the categories in the left sidebar just like

Now it is showing all the categories and sub categories. But I want all the category and subcategory should show the numbers of product in the respective category with it. So can someone kindly tell me how to do this? Any help and suggestions will be appreciable.

Upvotes: 0

Views: 3052

Answers (2)

Sushant Vishwas
Sushant Vishwas

Reputation: 61

Assuming that you want to display it in view.phtml you already have the current category object there so you can use $_category->getId()

$products_count = Mage::getModel('catalog/category')->load($_category->getId())
 ->getProductCount();

echo($products_count);

Upvotes: 1

dagfr
dagfr

Reputation: 2384

$collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($mycategory);

echo "(".count($collection).")";

Warning : $mycategory have to be an instance of Mage_Catalog_Model_Category, not an id.

Regards,

Upvotes: 0

Related Questions