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?
3 Answers
34
votes
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")
}
0
votes
You can get filter's attribute code or id through this code:
$appliedFilters = Mage::getSingleton('catalog/layer')->getState()->getFilters();
foreach ($appliedFilters as $item) {
echo $item->getFilter()->getAttributeModel()->getAttributeId();
echo $item->getFilter()->getAttributeModel()->getAttributeCode();
}