【问题标题】:Hiding or Showing Filters In Certain Categories in magento在magento中隐藏或显示某些类别的过滤器
【发布时间】:2014-01-08 11:44:25
【问题描述】:

在我们的最高级别类别中,大约有 50 个购物选项,我正在尝试在类别的自定义布局中使用 xml 代码隐藏属性过滤器。使用此代码

<reference name="em.catalog.leftnav">
<action method="setData">
    <instruction>hide_attribute_code</instruction>
    <value>1</value>
</action>

但不隐藏该类别中的过滤器属性,请查看图片

【问题讨论】:

    标签: magento attributes categories


    【解决方案1】:

    在目录.xml 中

     <catalog_category_layered translate="label">
        <label>Catalog Category (Anchor)</label>
        <reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
        </reference>
      <catalog_category_layered translate="label">
    

    按照模板...catalog/layer/view.phtml

    打开此文件并设置过滤器在前端显示的条件,按名称或 ID

               <?php $_filters = $this->getFilters() ?>
                <?php foreach ($_filters as $_filter): ?>
    
                           <?php if($_filter->getName() == 'Price' || $_filter->getName() == 'Category' || $_filter->getName() == 'Manufacturer' ): ?>   
                                  <?php if($_filter->getItemsCount()): ?>
                                       <dt><?php echo $this->__($_filter->getName()) ?></dt>
                                       <dd><?php echo $_filter->getHtml() ?></dd>
                                   <?php endif; ?>
                           <?php endif; ?>
    
                <?php endforeach; ?>
    

    【讨论】:

    • 我正在尝试但没有成功
    • 对我来说效果很好,您能发布您尝试过的哪些代码不适合您吗?
    • 如何隐藏所选产品类别的所选属性
    【解决方案2】:

    我不知道您的分层导航是否可靠,但这应该可以工作:

    <reference name="em.catalog.leftnav">
        <action method="hideAttributes">
            <code>hide_attribute_code</code>
        </action>
    </reference>
    

    转到app/code/POOL/YOUR/MODULE/Blocks/... 中构建您的过滤器的文件。如果您的模板有类似getFilters() 的内容,您可以尝试echo get_class($this) 来获取正确的类/文件。在那里你必须做两件事:

    1.) 添加一个新方法(在这种情况下您可以设置逗号分隔属性代码)

    public function hideAttributes($attributeCodes)
    {
        $attributeCodes = array_map('trim', explode(',', $attributeCodes));
        $this->setData('hide_attributes', $attributeCodes);
    }
    

    2.) 搜索收集过滤器的函数,例如getFilters() 并添加

    $filterableAttributes = // some code
    foreach ($filterableAttributes as $attribute) {
        if (!in_array($attribute->getAttributeCode(), $this->getHideAttributes())) {
            ...
        }
    }
    

    【讨论】:

      【解决方案3】:

      你需要取消设置视图层的属性名称,所以找到这个文件:

      magento/app/design/frontend/base/default/template/catalog/layer/view.phtml
      

      编辑:

      <?php if($this->canShowBlock()): ?>
      <div class="block block-layered-nav">
          <div class="block-title">
              <strong><span><?php echo $this->__('Shop By') ?></span></strong>
          </div>
          <div class="block-content">
              <?php echo $this->getStateHtml() ?>
              <?php if($this->canShowOptions()): ?>
                  <p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
                  <dl id="narrow-by-list">
                      <?php $_filters = $this->getFilters() ?>
                      <?php foreach ($_filters as $_filter): ?>
                      <?php if($_filter->getItemsCount()): ?>
                      <!--  add this line  start-->
                      <?php if($_filter->getName() != "Color"): ?>
                      <!--  add this line end-->
                      <dt><?php echo $this->__($_filter->getName()) ?></dt>
                      <dd>
                      <?php echo $_filter->getHtml() ?>
                      </dd>
                      <!--  add this line  start-->
                      <?php endif; ?>
                      <!--  add this line end-->
                      <?php endif; ?>
                      <?php endforeach; ?>
                  </dl>
                  <script type="text/javascript">decorateDataList('narrow-by-list')</script>
              <?php endif; ?>
          </div>
      </div>
      <?php endif; ?>
      

      希望你现在可以开始工作!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多