简体   繁体   English

Magento 1.7在同一页面上显示多个分层导航过滤器?

[英]Magento 1.7 Show Multiple Layered Navigation Filters on same page?

I am attempting to place the layered navigation in a strip in the header, as well as in the left sidebar. 我试图将分层导航放在标题中的条带中,以及左侧边栏中。 I am doing this by adding <block type="catalog/layer_view" template="catalog/layer/view.phtml"/> into head block of my page.xml file. 我这样做是通过将<block type="catalog/layer_view" template="catalog/layer/view.phtml"/>到我的page.xml文件的head块中。 While this works, when I click on a filter I get an error that boils down to the fact that Magento does not like more than one filter: 虽然这有效,但当我点击一个过滤器时,我得到的错误归结为Magento不喜欢多个过滤器的事实:

a:5:{i:0;s:64:"You cannot define a correlation name 'device_idx' more than once";i:1;s:3844:"#0 /home/sitea/subdomains/casefun/trunk/lib/Varien/Db/Select.php(281): Zend_Db_Select->_join('inner join', Array, 'device_idx.enti...', Array, NULL)

Followed by a stack trace. 随后是堆栈跟踪。

How do I add the layered navigation to a theme more than once without it breaking when I select a filter? 当我选择过滤器时,如何在不破坏主题的情况下多次将分层导航添加到主题中?

Unfortunately you can't display Layered Nav block more than once on one page. 遗憾的是,您无法在一个页面上多次显示分层导航块。 Every time the block is displayed, it applies filters to the Product collection. 每次显示块时,它都会将过滤器应用于Product集合。

Technically you can create a customization by extending standard Layered Nav block for your header or left placement and add a rule to NOT applyFilters , but this is not a simple task. 从技术上讲,您可以通过为标题或左侧放置扩展标准的Layered Nav块来创建自定义,并向NOT applyFilters添加规则,但这不是一项简单的任务。

I had to overwrite Mage_Catalog_Model_Resource_Layer_Filter_Attribute (in my local folder) to include a Singleton class: http://codepad.org/i2a1gL8i 我不得不覆盖Mage_Catalog_Model_Resource_Layer_Filter_Attribute(在我的本地文件夹中)以包含Singleton类: http ://codepad.org/i2a1gL8i

This allowed only one version of each filter to be created. 这样只允许创建每个过滤器的一个版本。

A new problem was created, though. 但是,创建了一个新问题。 In the list of currently applied filters, each filter was appearing twice. 在当前应用的过滤器列表中,每个过滤器出现两次。

http://i.imm.io/Gk4w.png http://i.imm.io/Gk4w.png

The fix to this was a LOT simpler. 解决这个问题的方法很简单。

In app/design/frontend/default/{theme}/template/catalog/layer/state.phtml add the following check: app/design/frontend/default/{theme}/template/catalog/layer/state.phtml添加以下检查:

<?php $appliedFilters = array(); ?>
<?php foreach ($_filters as $_filter): //existing line ?>
<?php
  if(in_array(strtolower($_filter->getName()), $appliedFilters))
  {
    continue; 
  }
  $appliedFilters[] = strtolower($_filter->getName());
?>

If a filter with the same name has already been listed, then do not list any other filters with the same name. 如果已列出具有相同名称的过滤器,则不要列出具有相同名称的任何其他过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM