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 ?

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.

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") – Pol Ravalitera Nov 29 '16 at 13:34
  • I guess this is the way to go. – Marius Nov 29 '16 at 13:34
  • 1
    In fact, i wrote a preference for categoryFilterList to my custom virtualType . it works too :) – Pol Ravalitera Nov 29 '16 at 13:36
  • nice. I never thought of that. – Marius Nov 29 '16 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 – Yonn Trimoreau Oct 11 '18 at 14:30

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.