How to show all attribute after layered navigation filter in Magento
April 10, 2015
Magento Layered Navigation is really good for filter the product but problem is that, if we select any attribute like color or price all other attribute hide which are not related to selected attribute. To show all the attribute after filter please use the below code.
In your frontend theme
catalog/template/catalog/layer/filter.phtml replace content with below code:
<ol>
<?php
$selection = FALSE;
$items = $this->getItems();
foreach ($this->getItems() as $_item)
{
if ($_item->isSelected())
{
$selection = TRUE;
$removal_url=$_item->getRemoveUrl();
break;
}
}
?>
<li>
<?php if ($selection): ?>
<a style="margin-top:2px; color: #666633" class="multi-select unselected" href="<?php echo $removal_url ?>"><?php echo $this->__('Show all') ?></a>
<?php else: ?>
<img style="margin-top:2px;" src="<?php echo $this->getSkinUrl('images/narrow_by_li_by.gif'); ?>"> <a style="color: #D96708" class="multi-select isselected" href="<?php echo $this->urlEscape($_item->getRemoveUrl()) ?>"><?php echo $this->__('Show all') ?></a>
<?php endif ?>
</li>
<?php foreach ($this->getItems() as $_item): ?>
<li>
<?php if( $_item->isSelected() ) : ?>
<img src="<?php echo $this->getSkinUrl('images/narrow_by_li_by.gif'); ?>"> <a style="color: #D96708" class="multi-select isselected" href="<?php echo $removal_url ?>"><?php echo $_item->getLabel() ?></a>
<?php else : ?>
<a style="color: #666633" class="multi-select unselected" href="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?></a>
<?php endif; ?>
</li>
<?php endforeach ?></ol>
In
view.phtml, just comment out below line:
<?php echo $this->getStateHtml() ?>
In
app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Layer/Filter/Attribute.php find the function
applyFilterToCollection and
Replace:
$tableAlias = $attribute->getAttributeCode() . '_idx';
With:
$tableAlias = $attribute->getAttributeCode() . '_idx_'.$value;
In apply in
app/code/core/Mage/Catalog/Model/Layer/Filter/Attribute.php , comment out below line:
$this->_items = array();
And replace the following in _getItemsData:
if ($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS)
with:
if (($this->_getIsFilterableAttribute($attribute) == self::OPTIONS_ONLY_WITH_RESULTS) && (!empty($optionsCount[$option['value']])))
Add the following method to
app/code/core/Mage/Catalog/Model/Layer/Filter/Item.php:
public function isSelected()
{
$selected = Mage::getSingleton('core/app')->getRequest()->getParam($this->getFilter()->getRequestVar());
if( $selected == $this->getValue() )
{
return true;
}
else
{
return false;
}
}
Look like all this big task to do but once you complete above you will see the magic.Happy Coding :)