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

发布于 2024-10-19 07:26:38 字数 565 浏览 4 评论 0原文

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

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

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

i want to show count of only configurable products of current category on category page. for that I have written following code...

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

my problem is the code is showing the total count of configurable products of all child categories... can anyone help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吐个泡泡 2024-10-26 07:26:38

试试这个

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

try this

<?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.")"; 
?>
落叶缤纷 2024-10-26 07:26:38
$category = Mage::registry('current_category');
$products = $category->getProductCollection()
          ->addAttributeToFilter('type_id', 'configurable');
$total = $products->getSize();
echo $this->__('%s (%d)', $category->getName(), $total);
$category = Mage::registry('current_category');
$products = $category->getProductCollection()
          ->addAttributeToFilter('type_id', 'configurable');
$total = $products->getSize();
echo $this->__('%s (%d)', $category->getName(), $total);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文