0

How can I get current category name when I am on a category page?

I tried some solutions, but they don't work when category is chosen from layered navigation. For example, if I click on category filter on left side - layered navigation, it returns URL: examplepage.com/sport/fitness.html?cat=40 and current category is Fitness, instead of Stepers.

When I go to category Stepers from main menu, the URL is: examplepage.com/sport/fitness/stepers.html and current category is Stepers, which is correct.

I hope it is understandable:)

  • in layered navigation categories links work as filter (like other product attributes). After click on category in layered navigation you stay on current category, but products will be filtered by category. – Max Sep 6 '17 at 13:10
  • Yes, I know that. But I want to achieve that also when clicking on filtering, it shows the category I chose. – Anitr Sep 7 '17 at 6:40
0

You can use layer filter to get the applied filters

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

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.