Magento Forum

Trying to get product count per category
 
lukemcr
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2008-08-18
 

I’m trying to show the product count per category in the breadcrumbs.

This is what I’m using, but for some reason it just shows the category_id instead of the count.

$cat_countcount Mage::registry('current_category');

$query 'SELECT COUNT(catalog_category_product_index.category_id) AS count FROM catalog_category_product_index WHERE catalog_category_product_index.category_id = '.print_r($cat_countcount['entity_id']).' GROUP BY catalog_category_product_index.category_id';

$query Mage::getSingleton('core/resource')->getConnection('core_read')->query($query); 

//and now you can build up your array or do anything you want (:

while($row=$query->fetch()) {
    $catCount[$row[
'category_id']]=$row['count'];
echo 
$row['count'];
}

Any ideas? There’s probably an already-built Magento function that does this that I’m missing somehow.

 
Magento Community Magento Community
Magento Community
Magento Community
 
centerax
Sr. Member
 
Avatar
Total Posts:  90
Joined:  2008-09-10
Montevideo, Uruguay
 

Hi,

Something like this should work:

Mage::getModel('catalog/category')->load($categoryId)->getProductCount();

Or (in your case) maybe just:

$cat_countcount->getProductCount();

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
sean14538
Member
 
Avatar
Total Posts:  32
Joined:  2009-11-04
Gouldsboro, PA
 

http://www.magentocommerce.com/boards/viewthread/66154/

This thread will help you out.
Sean

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

The thread suggested by sean14538 would help you even more if the forum moderator hadn’t deleted some posts.
Bad, bad moderator.

 
Magento Community Magento Community
Magento Community
Magento Community
 
magento123
Member
 
Avatar
Total Posts:  64
Joined:  2010-12-30
 

How to get total number of products of any specific category on cart page.

Thanks in Advance smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
d8bhatta
Member
 
Total Posts:  44
Joined:  2009-06-11
 

this may help you.

public function getProductCount($category)
{
$prodCollection = Mage::getResourceModel(’catalog/product_collection’)->addCategoryFilter($category);
Mage::getSingleton(’catalog/product_status’)->addVisibleFilterToCollection($prodCollection);
Mage::getSingleton(’catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($prodCollection);
return $prodCollection->count();
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kaushik Patel
Jr. Member
 
Total Posts:  28
Joined:  2011-12-24
 

check this…

http://hkpatel201.blogspot.in/2013/01/get-product-count-per-category.html

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top