5

I have seen lots of people who discussed about this issue, also given plenty of ideas, but i am still stuck at the issue. As per the answer at this link, i have written the new function to get the active filters value at view.php

app/code/local/Mage/Catalog/Block/Layer/View.php,

public function getActiveFilters()
    {
        $filters = $this->getLayer()->getState()->getFilters();
        foreach($filters as $filter){
            $active[] = $this->getChild($filter->getFilter()->getRequestVar().'_filter');
        }
        return $active;
    }

this function gives the value of the current filter name,label.

at view.phtml,

$_active = $this->getActiveFilters();

foreach ($_active as $active) {?>

   <select class="filter_box col-xs-12" onchange="filter(this.value)">
    <option value="#"><?php echo $this->__($active->getName()) ?></option>
    <?php echo $active->getHtml() ?>
    </select>
<?php }?>

In this link, @B00MER mentioned extending the filter class will solve the issue also provided the code for the Category Filter. I have checked it at my magento site, but there is no changes. It is just displaying the filter without any option.

I don't know how to achieve it, also don't know the method which i am using ,is correct or not.

Can someone point me the right solution for this issue.

Thanks.

1 Answer 1

6

To show filters all time in layered navigation, I have rewritten the magento catalog core classes, For Attribute Filters, rewrite class Mage_Catalog_Model_Resource_Layer_Filter_Attribute,

replace the following line at applyFilterToCollection function

$tableAlias = $attribute->getAttributeCode() . '_idx';

by,

$tableAlias = $attribute->getAttributeCode() . '_idx_'.$value;

rewrite the Mage_Catalog_Model_Layer_Filter_Attribute,

Comment Out the $this->_items = array(); at the function apply,

public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
    {
        $filter = $request->getParam($this->_requestVar);
        if (is_array($filter)) {
            return $this;
        }
        $text = $this->_getOptionText($filter);
        if ($filter && strlen($text)) {
            $this->_getResource()->applyFilterToCollection($this, $filter);
            $this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
            //$this->_items = array();
        }
        return $this;
    }

rewrite the Mage_Catalog_Model_Layer_Filter_Item to add the following method,

public function isSelected(){
        $selected = Mage::getSingleton('core/app')->getRequest()->getParam($this->getFilter()->getRequestVar());

        if($selected == $this->getValue()){
            return true;
        }else{
            return false;
        }
    }

isSelected() used for getting attribute clear url at the filter.phtml

The above steps will help to show all attributes at all time.

Ref:https://dhimandey.wordpress.com/2012/11/27/show-all-attributes-after-filter-in-layered-navigation/

For Price Filter,

rewrite the Mage_Catalog_Model_Layer_Filter_Price, comment out the else condition at the _getItemsData

protected function _getItemsData()
    {
        if (Mage::app()->getStore()->getConfig(self::XML_PATH_RANGE_CALCULATION) == self::RANGE_CALCULATION_IMPROVED) {
            return $this->_getCalculatedItemsData();

        } /*elseif ($this->getInterval()) {
            //return array();
        }*/

        $range      = $this->getPriceRange();
        $dbRanges   = $this->getRangeItemCounts($range);
        $data       = array();

        if (!empty($dbRanges)) {
            $lastIndex = array_keys($dbRanges);
            $lastIndex = $lastIndex[count($lastIndex) - 1];

            foreach ($dbRanges as $index => $count) {
                $fromPrice = ($index == 1) ? '' : (($index - 1) * $range);
                $toPrice = ($index == $lastIndex) ? '' : ($index * $range);

                $data[] = array(
                    'label' => $this->_renderRangeLabel($fromPrice, $toPrice),
                    'value' => $fromPrice . '-' . $toPrice,
                    'count' => $count,
                );
            }
        }

        return $data;
    }

This will helps to retain the price filter at all time. I hope this answer will help someone.

3
  • This is definitely the correct answer because it does what it says on the box, however there is one shortcoming, when filter is applied and you click on another filter option its not responsive. In other words filter is displayed, but it does not reapply filter if used again. Any solution to that?
    – K.I
    Feb 9, 2017 at 15:47
  • The numbers behind all filter options are "0" once a filter is selected for the attribute. Any fix for that?
    – Wouter
    Aug 17, 2017 at 7:51
  • how can i do the same in magento 2? Aug 13, 2020 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.