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" />

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

Here is full code to Override Magento\Catalog\Model\Layer\FilterList this class

I can use virtualType method for override instead of preference




<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Pradip_LayerModel" setup_version="0.1.0"/>        


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <virtualType name="categoryFilterList" type="Pradip\LayerModel\Model\Layer\FilterList">
            <argument name="filterableAttributes" xsi:type="object">Magento\Catalog\Model\Layer\Category\FilterableAttributeList</argument>



namespace Pradip\LayerModel\Model\Layer;

 * Override FilterList Class
class FilterList extends \Magento\Catalog\Model\Layer\FilterList
        public function getFilters(\Magento\Catalog\Model\Layer $layer)
            //echo "you can write code changes here"; exit;
            if (!count($this->filters)) {
                $this->filters = [
                    $this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
                foreach ($this->filterableAttributes->getList() as $attribute) {
                    $this->filters[] = $this->createAttributeFilter($attribute, $layer);
            return $this->filters;

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"/>

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.


I have following same but not working any guide please


<?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" />

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.