如何获得锚类别的产品数量?

时间:2012-04-05 20:46:44

标签: php magento

此代码仅适用于非锚类别 - 如何获取锚类别的产品计数?

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

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

    </h1></div>

2 个答案:

答案 0 :(得分:5)

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

var_dump($prodCollection->count());

答案 1 :(得分:2)

如下所示: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() 

将显示正确数量的产品