added 258 characters in body
Source Link
Giel Berkers
  • 11.4k
  • 6
  • 62
  • 111

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.

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();
}

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.

Source Link
Giel Berkers
  • 11.4k
  • 6
  • 62
  • 111

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();
}