Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Get total number of items of a category in view.phtml

How can I get the total number of Items, I want to show it in the category view.phtml file. Usually this value is in the Toolbar.phtml.

I have tried something like this, but I think I am pretty far away:

$this->helper('catalog/output')->$_productCollection->count()

Magento version 1.7.0.2

The expected result should be something like this:

Items in this category: 17 The 17 should be the total number. If possible should include subcategory items.

like image 411
Ignacio Correia Avatar asked Nov 28 '22 09:11

Ignacio Correia


2 Answers

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);

If you want to use it in list.phtml you can use

echo($_productCollection->count());
like image 191
Sergei Guk Avatar answered Dec 06 '22 07:12

Sergei Guk


Try this,

<?php $_helper = $this->helper('catalog/output');?>
<?php $_category_detail = Mage::registry('current_category');?>
<?php $_category_detail->getName();?>
<?php $_category_detail->getId(); ?>

<?php $products_count = Mage::getModel('catalog/category')->load($_category_detail->getId())
        ->getProductCount();
echo($products_count);
?>
like image 26
Hardik Avatar answered Dec 06 '22 06:12

Hardik