Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Get Selected Filter In Layered Navigation

Tags:

php

magento

In Magento, if "color" attribute is chosen in layered navigation, values of the "color" are automatically disappears and results are getting displayed.How to retrieve the name of the selected filter?

like image 787
blakcaps Avatar asked Aug 08 '12 10:08

blakcaps


1 Answers

All the applied filters are stored in layer state object. You can easily retrieve them by using the following snippet:

$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();

It will return you an array of filter item objects. You can retrieve name and applied value of a single filter item by doing something like this:

foreach ($appliedFilters as $item) {
    $item->getName(); // Name of the filter
    $item->getLabel(); // Currently selected value
    $item->getFilter()->getRequestVar(); // Filter code (usually attribute code, except category filter, where it equals "cat")
}
like image 132
Ivan Chepurnyi Avatar answered Oct 05 '22 19:10

Ivan Chepurnyi