0
votes

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.

2
This question is more or less a duplicate of stackoverflow.com/questions/272818/… the difference being that you should call $products->count() to get the count.Domen Vrankar

2 Answers

1
votes

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);
0
votes
$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,