2

I'm trying to remove the category filter in category view. But apart from that, my question is more about Magento 2 itself.

in di.xml of Magento_CatalogSearch , you just have to comment the "category" item to do that :

<virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
 <arguments>
 <argument name="filters" xsi:type="array">
 <item name="attribute" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Attribute</item>
 <item name="price" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Price</item>
 <item name="decimal" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Decimal</item>
 <item name="category" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Category</item>
 </argument>
 </arguments>
</virtualType>

So I was trying to remove this argument, in a custom module, just copy/pasting it into my di.xml and removing the item category. But it does not work.

And yes, I wrote well my module.xml, with the sequence and depends nodes.

Is this possible, or do i have to do another Virtual Type? This way I could write a preference for categoryFilterList, but is this possible to modify an existing argument ?

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Nov 29, 2016 at 13:26

1 Answer 1

3

the di.xml files are merged, so it if you copy the markup you mentioned in your module and remove a line, when the merge is done, the original file will be merge too and you will still get that line.

An option would be to create your own virtual type that does not contain the category item and make all the models that used the original catalogFilerList virtual type, use your own.
Something like this:

<virtualType name="MyCustomCategoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
 <arguments>
 <argument name="filters" xsi:type="array">
 <item name="attribute" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Attribute</item>
 <item name="price" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Price</item>
 <item name="decimal" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Decimal</item>
 <item name="category" xsi:type="string">Magento\CatalogSearch\Model\Layer\Filter\Category</item>
 </argument>
 </arguments>
</virtualType>

Then in the frontend/di.xml of your module add this:

 <virtualType name="Magento\LayeredNavigation\Block\Navigation\Category" type="Magento\LayeredNavigation\Block\Navigation">
 <arguments>
 <argument name="filterList" xsi:type="object">MyCustomCategoryFilterList</argument>
 </arguments>
</virtualType>

That's the only one I found that uses categoryFilterList.

answered Nov 29, 2016 at 13:32
5
  • Yeah i did that, wrote down a new VirtualType. But you have to copy/paste another line of the Magento_Catalog concerning categoryFilterList (argument name="filterableAttributes") Commented Nov 29, 2016 at 13:34
  • I guess this is the way to go. Commented Nov 29, 2016 at 13:34
  • 1
    In fact, i wrote a preference for categoryFilterList to my custom virtualType . it works too :) Commented Nov 29, 2016 at 13:36
  • nice. I never thought of that. Commented Nov 29, 2016 at 13:36
  • Marius, you need to add this argument to your custom "MyCustomCategoryFilterList" virtualType: <argument name="filterableAttributes" xsi:type="object">Magento\Catalog\Model\Layer\Category\FilterableAttributeList</argument> Otherwise, M2 will return a 500 error Commented Oct 11, 2018 at 14:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.