2011-02-25 102 views
1

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

<?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.")"; ?> 

我的问题是代码表明所有子类配置的产品的总数...谁能帮助我?

+0

是有问题的类别锚类别? – clockworkgeek 2011-02-25 22:46:47

+0

是的,这是一个锚类别.. – hs19 2011-03-04 04:34:41

回答

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.")"; 
?> 
+0

感谢oliver但与此代码也我有同样的问题.. – hs19 2011-02-25 13:15:51

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

同样的问题....我认为可能有一些问题,由行'$ category返回的对象= Mage :: registry('current_category');'我试图使用print_r打印结果,但它什么也没有显示.... – hs19 2011-02-28 03:52:00

+0

打印复杂对象可能会遇到溢出或内存限制问题,请尝试使用print_r($分类 - >调试())' – clockworkgeek 2011-02-28 04:56:44

相关问题