0

How to get active filters using observer on product listing page, what is the procedure to get that?

0

1 Answer 1

1

You can call event catalog_product_collection_load_before on listing page

you can get active filter like this :-

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$stateFilter = $objectManager->create('\Magento\LayeredNavigation\Block\Navigation\State');
$selectedFilters = $stateFilter->getActiveFilters();
foreach($selectedFilters as $filter){
    echo $filter->getName(); // Color etc
    echo $filter->getLabel(); // Black etc
}
10
  • Where i can put the above code?
    – zus
    Jan 28, 2021 at 7:31
  • create event catalog_product_collection_load_before Jan 28, 2021 at 7:34
  • can you pls join the chat chat.stackexchange.com/rooms/119033/…
    – zus
    Jan 28, 2021 at 8:35
  • Shall i put log for what attributes selected using echo $filter->getName();
    – zus
    Jan 28, 2021 at 12:55
  • Where i can add your code?
    – zus
    Jan 29, 2021 at 1:45

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.