首页 文章

如何在magento 2.2.3中覆盖Magento \ Catalog \ Model \ Layer \ FilterList

提问于
浏览
0

使用插件覆盖Magento 2.2.3中的 Magento\Catalog\Model\Layer\FilterList . 这个错误来了

PHP消息:PHP致命错误:未捕获TypeError:参数2传递给#### \ Plugin \ Model \ Layer \ FilterList :: aroundGetFilters()必须实现接口Magento \ Catalog \ Model \ Layer \ FilterableAttributeListInterface,给出Closure的实例,在第135行的/magento/framework/Interception/Interceptor.php中调用,并在#### / Plugin / Model / Layer / FilterList.php中定义:70

首选项不适用于此文件 .

2 回答

  • 0

    使用virtual_type

    一旦验证传递的di.xml参数的核心文件

    .... / modulename / extensionmodule / etc / frontend / di.xml

    <virtualType name="categoryFilterList" type="ModuleName\ExtensionModule\Model\Layer\FilterList">
        <arguments>
        Your Passing Arguments(same as existing core file - di.xml(core module) passing arguments ).
    
        </arguments>
    </virtualType>
    

    .... / modulename / extensionmodule / Model \ Layer

    <?php
    
        namespace ModuleName\ExtensionModule\Model\Layer;
    
        /**
         * Override FilterList Class
         */
        class FilterList extends \Magento\Catalog\Model\Layer\FilterList
        {
            ......Your Code Here......
        }
        ?>
    
  • 1

    您无法通过插件覆盖该类 . 如果要覆盖该类,则只需在di.xml中使用以下代码即可

    <preference for="Magento\Catalog\Model\Layer\FilterList" type="NAMESPACE\YOUR_MODULE\Model\Layer\FilterList" />
    

    如果这不起作用,那么转到父类(Magento \ Catalog \ Model \ Layer \ FilterList)并检查您从模块的FilterList.php的__contruct函数发送的arugments的数量 . 将具有相同顺序的相同数量的参数传递给父类 . 它会工作 .

相关问题