5

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.

  • any helps ????? – Michel Gokan Aug 5 '16 at 5:30
  • Hi michel Gokan did u implement this concept in magento 2 api level? – Nagaraju Kasa Mar 14 '18 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. – Michel Gokan Mar 14 '18 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 – Nagaraju Kasa Mar 14 '18 at 11:17
  • Please find the below link , i need to implement an api for magento 2 magento.stackexchange.com/questions/217261/… – Nagaraju Kasa Mar 14 '18 at 11:17
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.