Magento 1.9 – How to Get Active Filters Attribute Code in state.phtml

magento-1.9

I have been working on Magento C.E 1.9.0.2, and I am implementing custom AJAX product loader, I have achieved everything but I am not able to filter out my product collection as per the selected filters. All I need to have the attribute code of selected filters, which I think can be achieved from state.phtml, where we have the active filters. But, I am not able to get the correct method to to get the active filter's attribute code and current selected values. Need help….

Best Answer

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

and you get fetch like that

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")
}

reference

Related Topic