php-Magento类别上的唯一有效产品计数
作者:互联网
我试图显示每个类别中的产品数量,使用此代码来显示类别id:3的子类别.它正在显示,但其中包括残疾人和隐形产品.
<?php
$cats = Mage::getModel('catalog/category')->load(3)->getChildrenCategories();
?>
<ul>
<?php foreach($cats as $category): ?>
<li>
<a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?>(<?php echo $category->getProductCount(); ?>)</a>
</li>
<?php endforeach; ?>
</ul>
有什么好的解决方案,以便我可以准确地了解已启用和活动的类别.
解决方法:
you need check active filter acondition and for this you can use below code
$products = Mage::getModel('catalog/category')->load($category->getId())
->getProductCollection()
->addAttributeToSelect('entity_id')
->addAttributeToFilter('status', 1)
->addAttributeToFilter('visibility', 4);
echo $products->count();
标签:magento,magento-1-7,php 来源: https://codeday.me/bug/20191030/1970932.html