仅显示当前类别的可配置产品的数量

时间:2011-02-25 07:19:06

标签: magento categories product

我想在类别页面上显示当前类别的可配置产品的数量。为此,我写了以下代码......

<?php $cate = Mage::registry('current_category')->getName();

                $total=0;


               $category = Mage::registry('current_category');

               $products = $category->getProductCollection();

              foreach ( $products as $_product )
                 if ($_product->isConfigurable())
                 {
                    $total++;
                 }
                 echo $cate."(".$total.")"; ?>

我的问题是代码显示了所有子类别的可配置产品的总数...有人可以帮我这个吗?

2 个答案:

答案 0 :(得分:0)

试试这个

<?php 
$cate       = Mage::registry('current_category')->getName();
$total      = 0;
$category   = Mage::registry('current_category');

$products = $category->getProductCollection();

foreach ( $products as $_product ){
    if ($_product->getType_id()=="configurable"){
        $total++;
    }
}
 echo $cate."(".$total.")"; 
?>

答案 1 :(得分:0)

$category = Mage::registry('current_category');
$products = $category->getProductCollection()
          ->addAttributeToFilter('type_id', 'configurable');
$total = $products->getSize();
echo $this->__('%s (%d)', $category->getName(), $total);