error in catalog view layered navigation filter
-
07-10-2020 - |
Question
This is the block from my catalogsearch.xml
<reference name="left">
<block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
The selected filters are displaying multiple time.I tried changing the type and still no change, Please Help.
update :
in my catalog\layer\state.phtml
$_filters = $this->getActiveFilters();
count($_filters)
is returning me 3 which should be only one .Please help why this is happening
Solution
check the xml for duplicate catalogsearch.leftnav
block
OTHER TIPS
You'll need to loop over the $_filter
results most likely just like the RWD theme does in state.phtml
$_filters = $this->getActiveFilters();
$_renderers = $this->getParentBlock()->getChild('state_renderers')->getSortedChildren();
?>
<?php if(!empty($_filters)): ?>
<div class="currently">
<p class="block-subtitle"><?php echo $this->__('Currently Shopping by:') ?></p>
<ol>
<?php foreach ($_filters as $_filter): ?>
<?php
$_rendered = false;
foreach ($_renderers as $_rendererName):
$_renderer = $this->getParentBlock()->getChild('state_renderers')->getChild($_rendererName);
if (method_exists($_renderer, 'shouldRender') && $_renderer->shouldRender($_filter)):
$_renderer->setFilter($_filter);
echo $_renderer->toHtml();
$_rendered = true;
break;
endif;
endforeach;
...
- https://github.com/OpenMage/magento-mirror/blob/505e8e982ad5f4fd22005060564cad210aab7b6f/app/design/frontend/rwd/default/template/catalog/layer/state.phtml#L36-L53
- https://github.com/OpenMage/magento-mirror/blob/505e8e982ad5f4fd22005060564cad210aab7b6f/app/code/core/Mage/Catalog/Block/Layer/State.php#L51
Also, every filter renderer is where the list of states are collected, and also notice the use of getItemsCount
instead of native PHP count
, avoid using count
on the ORM/Collections as they have big performance impacts:
protected function _initFilter()
{
if (!$this->_filterModelName) {
Mage::throwException(Mage::helper('catalog')->__('Filter model name must be declared.'));
}
$this->_filter = Mage::getModel($this->_filterModelName)
->setLayer($this->getLayer());
$this->_prepareFilter();
Related:
You need to edit the file mentioned below, in the current theme
/app/design/frontend/PACKAGE/THEME/template/catalog/layer/state.phtml
This is the actual code:
$_renderers = $this->getParentBlock()->getChild('state_renderers')->getSortedChildren();
Replace by:
$_renderers = $this->getParentBlock()->getChild('state_renderers');
layout-catalogsearch.xml Comment out a part of the code, clean the cache.
<catalogsearch_result_index translate="label">
<label>Quick Search Form</label>
<reference name="root">
<action method="setTemplate"><template>page/3columns.phtml</template></action>
</reference>
<!--<reference name="left">-->
<!--<block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml">-->
<!--<block type="core/text_list" name="catalog.leftnav.state.renderers" as="state_renderers" />-->
<!--</block>-->
<!--</reference>-->
<reference name="content">
`enter code here`