Magento在工具栏中按子类别添加过滤器
我试图用子类别筛选产品列表,比如说我有一个名为Magento在工具栏中按子类别添加过滤器,magento,custom-controls,product,Magento,Custom Controls,Product,我试图用子类别筛选产品列表,比如说我有一个名为香水的顶级类别,为他和她的子类别。在顶级分类列表页面中,我试图包括名为筛选结果的选项,它应该显示一个下拉列表,男性和女性均为 如果用户单击男性的,则应仅显示男性类别中的产品 为了做到这一点,我试着 <?php $categories = Mage::getModel('catalog/category')->getCollection() ->addAttributeToSelect('name')
香水的顶级类别
,为他和她的子类别。在顶级分类列表页面中,我试图包括名为筛选结果的选项
,它应该显示一个下拉列表,男性和女性均为
如果用户单击男性的
,则应仅显示男性类别中的产品
为了做到这一点,我试着
<?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/>
()
但它显示了所有类别的产品数量。
是否有人知道如何筛选此项以仅显示当前主类别的子类别
谢谢。
<?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 ?>
您到底在哪里插入了此代码?我在我的themes view.phtml文件下插入了此代码……您能提供完整路径吗?Magento中有几个view.phtml。嗨,tim,我在frontend/My Theme/default/template/catalog/category/view.phtml下添加了这些代码。实际上,我正在尝试按子类别筛选产品列表