I have a category with some subcategories:
- Lamps
-- Hanging lamps
-- Wall lamps
-- Floor lamps
When clicking on one of the three subcategories in the Layered Navigation, the product listing is filtered to the products of that specific category. I don’t want it to filter, but I want the subcategories in the Layered Navigation to actually link to the category.
Is this a Magento 2 setting, or does this require custom changes? If so, can anybody help me get started? I’ve done some searching, but was only able to find a similar question for Magento 1.
2
Answers
You need to use a custom plugin class. Where you can change the core behavior of
getUrl
method inMagentoCatalogModelLayerFilterItem
class. Because thisgetUrl
method is responsible for generating all filter URLs.Here
after
plugin method (afterGetUrl
) is used. Which runs after the main method (getUrl
).If you want to know more about plugin class. You can check here.
I am working on magento 2.3.3 – 2.3.4 and this solution does not work for me,
but it was very helpful. I need to change the code little bit.
here is my fix:
I hope it will be helpful as it was for me.