0

我正在尝试使用子类别过滤产品列表,可以说我有一个名为的顶级类别perfume和名为for him&的子类别for her。在顶级类别列表页面中,我试图包含名为它的选项filter results,它应该显示一个下拉列表for men and for women

如果用户点击for men它应该只显示产品for men category

为此,我尝试过,

<?php $categories = Mage::getModel('catalog/category')->getCollection()
         ->addAttributeToSelect('name')
         ->addAttributeToSelect('url_key')
         ->addAttributeToSelect('my_attribute')
         ->addAttributeToSelect('position')
         ->addAttributeToSort('position', 'ASC')
         ->setLoadProductCount(true)
         ->addAttributeToFilter('is_active',array('eq'=>true))
         ->load(); ?><?php foreach($categories as $key=>$category): ?><?php if($category->getName() != ''):?>    <?php $prodCollection = age::getResourceModel('catalog/product_collection')->addCategoryFilter($category); // Magento product collection ?>
<a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a> (<?php echo $prodCollection->count() ?>)<br/>

但它显示了所有类别的产品数量。有谁知道如何过滤这个以仅显示当前主要类别的子类别?

谢谢,。

4

1 回答 1

0
<?php

    $rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
    $categories = Mage::getModel('catalog/category')->getCategories($rootCategoryId);

?>
<?php foreach($categories as $category): ?>
    <a href="<?php echo $category->getUrl() ?>"><?php echo $category->getName() ?></a><br/>
<?php endforeach ?>
于 2012-07-05T08:10:46.130 回答