1

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

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

我可以添加分层导航块

        <reference name="left">
           <block type="catalog/layer_view" name="catalog.leftnav" template="landing/layer.phtml"/>
        </reference>

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

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

4

2 回答 2

1

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

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

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

于 2012-12-16T12:06:10.760 回答
0

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

{{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(就像我在这里所做的那样)。虽然,我没有为自定义集合构建一个功能来显示这一点,但我相信遵循“目录/层”模型并查看集合的加载位置,您可以看到如何覆盖它并加载您自己的自定义集合.

于 2015-09-04T09:47:56.473 回答