6

I'm going to write a block to put in products list page. My question is how can I get to know which layered navigation filters are currently applied in the current list page ?

Any help will be appreciated.

5
  • any helps ????? Commented Aug 5, 2016 at 5:30
  • Hi michel Gokan did u implement this concept in magento 2 api level? Commented Mar 14, 2018 at 7:00
  • @NagarajuKasa Did you try Giel's solution below? I asked this question about 2 years ago and I'm not working with Magento anymore but his solution works like a charm on that time. However, Magento evolved too much and I was working with 2.1 version. Commented Mar 14, 2018 at 11:09
  • thanks for your comments @michel, may i know whether the below concept will work for an API level? do u have any idea thanks Commented Mar 14, 2018 at 11:17
  • Please find the below link , i need to implement an api for magento 2 magento.stackexchange.com/questions/217261/… Commented Mar 14, 2018 at 11:17

1 Answer 1

4

You can do this with the layer resolver (Magento\Catalog\Model\Layer\Resolver). Example code:

public function __construct(
    \Magento\Catalog\Model\Layer\Resolver $layerResolver
)
{
    $this->layerResolver = $layerResolver;
    $layer = $this->layerResolver->get();
    $activeFilters = $layer->getState()->getFilters();
}

Edit:

A small sidenote to those who might concern: you can only get the state after \Magento\Catalog\Controller\Category\View::execute() has already created the state. Otherwise you get a Catalog Layer has been already created runtime exception.

2

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.