【问题标题】:Magento Add filter by subcategory in tool barMagento 在工具栏中按子类别添加过滤器
【发布时间】:2012-07-05 16:10:46
【问题描述】:

我正在尝试使用子类别过滤产品列表,假设我有一个名为 perfume 的顶级类别和名为 for himfor 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/>

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

谢谢,。

【问题讨论】:

  • 这段代码你到底是在哪里插入的?
  • 我在我的主题 view.phtml 文件下插入了这段代码......
  • 能否提供完整路径? Magento 中有几个 view.phtml。
  • 嗨蒂姆,我在frontend/My-Theme/default/template/catalog/category/view.phtml下添加了这些代码实际上我正在尝试按子类别过滤产品列表,例如markavip.com/campaigns/1207drd.html

标签: magento custom-controls product


【解决方案1】:
<?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 ?>

【讨论】:

    猜你喜欢
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多