How to get product count for anchor category?

Go To StackoverFlow.com

0

This code works only for non anchor categories - how can I get the product count of anchor category?

<div class="grid_16"><h1 class="highlight pageTitle"><?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?>

        <span>
            (<?php echo $_category->getProductCount() ?>)
        </span>

    </h1></div>
2012-04-05 20:46
by Federico
http://www.magentocommerce.com/boards/viewthread/200940/#t27024 - Paul Dessert 2012-04-05 20:50
check document, there is a method which is count anchor and nonanchor [http://docs.magentocommerce.com/MageCatalog/MageCatalogModelResourceEavMysql4CategoryCollection.html - Oğuz Çelikdemir 2012-04-06 09:09


5

$prodCollection = Mage::getResourceModel('catalog/product_collection')->addCategoryFilter($category); 

var_dump($prodCollection->count());
2012-04-28 07:47
by Alex
Hello, this work fine tk, just a problem, the count include disabled products, how i can remove this - Federico 2012-07-12 21:39
Need add filter like - statu - Alex 2012-07-15 21:30
Need add filter, like - status. But if you want use Resourse model, this is very bad solution, becouse will very depend with speed of Magento. Use only Models - Alex 2012-07-15 21:36


2

As seen here : magento forum

$category_object = Mage::getModel('catalog/category')->load( CATEGORY_ID ); // If you don't already have one
$total = Mage::getModel('catalog/layer')->setCurrentCategory( $category_object )->getProductCollection()->getSize() 

Will show correct number of products

2013-07-24 16:03
by baoutch
Ads