【问题标题】:Magento - Adding layered navigation to custom pageMagento - 向自定义页面添加分层导航
【发布时间】:2012-12-04 12:41:41
【问题描述】:

我正在开发一个 magento 模块,该模块在新控制器和前台名称下显示特定产品集合。

其中一些集合变得很大,所以我想在页面的一侧添加分层导航。 (嘿,分页和排序。)

我可以用

添加分层导航块
        <reference name="left">
           <block type="catalog/layer_view" name="catalog.leftnav" template="landing/layer.phtml"/>
        </reference>

我得到的是应用于整个目录的分层导航,类别被破坏,并且没有与页面产品集合的界面。

我将如何将分层导航(以及嘿,分页和排序)连接到这个自定义产品集合?

【问题讨论】:

    标签: magento


    【解决方案1】:

    这里没有答案,我改变了方向,从未完成过这条发展道路。我想我会发布我学到的东西。

    上面的方法是合理的。这项工作基本上需要在目录或目录搜索模块上重新创建功能。您必须对目录的模型和块进行子类化,修改产品集合和当前类别。

    这篇文章的方向模糊不清,但没有到达那里。
    http://www.webdesign-gm.co.uk/news/layered-navigation-on-home-page-or-any-cms-page-magento.php 如果您在这方面取得了更多进展,请随时发布。

    【讨论】:

      【解决方案2】:

      我收到了来自客户的类似请求,要求在大型菜单下包含特定的可过滤属性。 使用静态块,我已将此行添加到我需要特定类别的属性列表的任何地方

      {{block type="core/template" attribute_code="age_specific" category_id="12"  template="megamenu-custom-filter-list.phtml"}}
      

      然后是“megamenu-custom-filter-list.phtml”

      <?php if($this->getCategoryId() && is_numeric($this->getCategoryId()) && $this->getAttributeCode()): ?>
       <?php
        $visible_items = 12;
        $category = Mage::getModel('catalog/category')->load($this->getCategoryId());
        $attrCode = $this->getAttributeCode();
        unset($layer);
        $layer = Mage::getModel("catalog/layer");
        $layer->setCurrentCategory($category);
        $attributes = $layer->getFilterableAttributes();
        foreach ($attributes as $attribute):
          if($attribute->getAttributeCode() != $attrCode){
            continue;
          }
          if ($attribute->getAttributeCode() == 'price') {
            $filterBlockName = 'catalog/layer_filter_price';
          } elseif ($attribute->getBackendType() == 'decimal') {
            $filterBlockName = 'catalog/layer_filter_decimal';
          } else {
            $filterBlockName = 'catalog/layer_filter_attribute';
          }
          $result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
       ?>
          <div>
            <h4 class="menu-block-title"><?php echo $this->__($attribute->getFrontendLabel()) ?></h4>
            <ul class="menu-attr-list">
              <?php $counting = 1; ?>
              <?php foreach($result->getItems() as $option): ?>
                <?php $optionUrl = $category->getUrl() . "?" . $attribute->getAttributeCode() . "=" . $option->getValue(); ?>
                <?php if(!$option->getCount()){ continue; } ?>
                <li class="<?php echo ($counting >= $visible_items+1)?"visible-on-showmore":"" ?>" style="list-style: none;">
                  <a class="cube" href="<?php echo $optionUrl ?>">
                    <?php echo $option->getLabel() ?> <?php /* (<?php echo $option->getCount() ?>) */ ?>
                  </a>
                </li>
                <?php $counting++; ?>
              <?php endforeach; ?>
              <?php if($counting >= $visible_items+1): ?>
                <li class="show-more-menuitem">
                  <a href="javascript:void(0)" onclick="showMoreMenuItems(this); return false;" class="">
                    <?php echo $this->__('Visa fler') ?>
                  </a>
                </li>
              <?php endif; ?>
            </ul>
          </div>
       <?php endoreach; ?>
      <?php endif; ?>
      

      当然,这可以扩展为允许显示所有属性,而不是将它们限制为 12 个(就像我在这里所做的那样)。虽然,我没有为自定义集合构建一个功能来显示这个,但我相信遵循“目录/层”模型并查看集合的加载位置,您可以看到如何覆盖它并加载您自己的自定义集合.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-15
        • 2011-06-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多