1

I am using Magento2.3.1 and i trying to override model in our theme.

our model file path app/code/XXXX/General/Model/Layer

<?php
namespace XXXXX\General\Model\Layer;

class FilterList extends \Magento\Catalog\Model\Layer\FilterList
{
    public function getFilters(\Magento\Catalog\Model\Layer $layer)
    {
        if (!count($this->filters)) {
            $this->filters = [
                $this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
            ];
            $i = 1;
            foreach ($this->filterableAttributes->getList() as $attribute) {
             echo "test";   
           }    

        }
        return $this->filters;
    }
}

app/code/XXXXX/General/etc our di.xml file path and below code

<?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="\XXXX\General\Model\Layer\FilterList" />    
</config>

please check it my code and reply me how to wrong?

  • <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Model\Layer\FilterList" type="XXXX\General\Model\Layer\FilterList" /> </config> Please remove \ from type as above and try again. – Ronak Oct 7 at 10:45
  • i already remove it \ from type inside but not working on it – Rv Singh Oct 7 at 10:47
  • @RvSingh might this will help you. stackoverflow.com/questions/50004762/… – Nits Oct 11 at 13:51
2

same issue not override that file,

I have follow same as per above but not working need to override this : Magento\Catalog\Model\Layer\FilterList

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

0

Using virtual_type

Once Verify the core file of di.xml arguments passing \vendor\magento\module-catalog\etc

<!-- replace this code with your di.xml -->
<!-- For Category Filter -->
 <virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList">
        <arguments>
            <argument name="filterableAttributes" xsi:type="object">XXXX\General\Model\Layer\FilterList</argument>
        </arguments>
    </virtualType>

<!-- For search filter -->
    <virtualType name="searchFilterList" type="Magento\Catalog\Model\Layer\FilterList">
        <arguments>
            <argument name="filterableAttributes" xsi:type="object">XXXX\General\Model\Layer\FilterList</argument>
        </arguments>
    </virtualType>

.../modulename/extensionmodule/Model\Layer

<?php

    namespace XXXX\Genera\Model\Layer;

    /**
     * Override FilterList Class
     */
    class FilterList extends \Magento\Catalog\Model\Layer\FilterList
    {
        ......Your Code Here......
    }
    ?>
  • can you please explain properly so i am confusing where is put it code <virtualType name="categoryFilterList" type="Magento\Catalog\Model\Layer\FilterList"> <arguments> <argument name="filterableAttributes" xsi:type="object">Magento\Catalog\Model\Layer\Category\FilterableAttributeList</argument> like code – Rv Singh Oct 7 at 11:16
  • code updated please have a look – Ranjeet Kumar Oct 7 at 11:38
  • code is not working it – Rv Singh Oct 7 at 13:10

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.