Reputation: 13333
I am pretty newbie to the magento. I want to show the number of products in the categories in the left sidebar just like
Product-1 (21)
Product-2 (11)
Product-3 (16)
Product-4 (68)
So for showing all the products with category and its sub category I made my left_nav.phtml
file which is inside the folder location app/design/frontend/my-theme/default/template/catalog/navigation/
something like this
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
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
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