1

In my custom module, I'm trying to override Magento\Catalog\Model\Layer\FilterList class (more precisely: I want to override function getFilters).

In the module's etc\di.xml there are:

  1. One plugin statement
  2. One preference statement

The plugin is working perfect, while preference is completely ignored.

    <preference for="Magento\Catalog\Model\Layer\FilterList" type="\vendor\module\Model\Layer\FilterList"/>

<type name="Magento\Catalog\Model\Product">
    <plugin name="logProductName" type="\vendor\module\Plugin\ProductName" />
</type>

I double checked all class references - all's good. Please let me know what I'm missing.

Thank you very much!

  • 1
    Why you are overriding this method ? You can use simply plugin feature because this getFilters method is public – Keyur Shah Nov 10 '16 at 9:56
  • I know it's public. However, in my case is simplier to use overriding. Any ideas? – Pete Jaworski Nov 10 '16 at 11:25
  • Just use around plugin and don't call original method($procede() closure) , and do your magic :) – Keyur Shah Nov 10 '16 at 11:56
  • Thanks Keyur. Just done it with plugin. I'm not calling the original method. I do my magic ;) - However, I have problem with accessing protected variables. How do I access them? – Pete Jaworski Nov 10 '16 at 13:51
  • You can define protected variable in your file and Inject \Magento\Catalog\Model\Layer\FilterList into constructor so you can call createAttributeFilter () method – Keyur Shah Nov 10 '16 at 13:57
0

May be below code is work for you.

 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
     <preference for="Magento\Catalog\Model\Layer\FilterList" type="Vendor\Module\Model\Layer\FilterList"/>
 </config>

use this instead of

 <preference for="Magento\Catalog\Model\Layer\FilterList" type="\Vendor\Module\Model\Layer\FilterList"/>

and make sure you have to re-compile, or remove var/di, var/generation etc.

and you have to extends this \Magento\Catalog\Model\Layer\FilterList core class in your custom class.

0

I have following same but not working any guide please

di.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Catalog\Model\Layer\FilterList" type="Mageone\Filterlist1\Rewrite\Magento\Catalog\Model\Layer\FilterList" />
</config>



<?php
namespace Mageone\Filterlist1\Rewrite\Magento\Catalog\Model\Layer;
class FilterList extends \Magento\Catalog\Model\Layer\FilterList
{
   public function getFilters(\Magento\Catalog\Model\Layer $layer)
    {
        //need to customise here
    }
}

can you please anyone help

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.