0

I have plugin that works fine in magento 2.3 but in magento 2.4 i am getting below error :

Argument 3 passed to Magento\Catalog\Model\Layer\FilterList::__construct() must be an instance of Magento\Catalog\Model\Config\LayerCategoryConfig, array given Shopby/Model/Layer/FilterList.php on line 77

code of filterlist.php as below :

use Magento\Catalog\Model\Layer;
use Magento\Store\Model\ScopeInterface;
use Amasty\Shopby\Model\Source\VisibleInCategory;

class FilterList extends Layer\FilterList
{
    const PLACE_SIDEBAR = 'sidebar';
    const PLACE_TOP     = 'top';
    const ALL_FILTERS_KEY     = 'amasty_shopby_all_filters';

    /**
     * @var \Amasty\Shopby\Helper\FilterSetting\Proxy
     */
    private $filterSetting;

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    private $scopeConfig;

    /**
     * @var \Magento\Framework\App\Request\Http
     */
    private $request;

    /**
     * @var string
     */
    private $currentPlace;

    /**
     * @var bool
     */
    private $filtersLoaded  = false;

    /**
     * @var bool
     */
    private $filtersMatched = false;

    /**
     * @var bool
     */
    private $filtersApplied = false;

    /**
     * @var  \Magento\Framework\Registry
     */
    private $registry;

    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        Layer\FilterableAttributeListInterface $filterableAttributes,
        \Amasty\Shopby\Helper\FilterSetting\Proxy $filterSettingHelper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\Request\Http $request,
        \Magento\Framework\Registry $registry,
        array $filters = [],
        $place = self::PLACE_SIDEBAR
    ) {
        $this->currentPlace = $place;
        $this->filterSetting = $filterSettingHelper;
        $this->scopeConfig = $scopeConfig;
        $this->request = $request;
        $this->registry = $registry;
        parent::__construct($objectManager, $filterableAttributes, $filters);
    }

Error is on line parent::__construct($objectManager, $filterableAttributes, $filters);

Please help with what we need to change

1 Answer 1

1

Parent construct has been changed in Magento 2.4 version as below

/**
     * @param \Magento\Framework\ObjectManagerInterface $objectManager
     * @param FilterableAttributeListInterface $filterableAttributes
     * @param LayerCategoryConfig $layerCategoryConfig
     * @param array $filters
     */
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        FilterableAttributeListInterface $filterableAttributes,
        LayerCategoryConfig $layerCategoryConfig,
        array $filters = []
    ) {
        $this->objectManager = $objectManager;
        $this->filterableAttributes = $filterableAttributes;
        $this->layerCategoryConfig = $layerCategoryConfig;

        /** Override default filter type models */
        $this->filterTypes = array_merge($this->filterTypes, $filters);
    }

In your parent construct you need to pass dependency to parent as below. Change your construct code same as below

public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        Layer\FilterableAttributeListInterface $filterableAttributes,
        \Magento\Catalog\Model\Config\LayerCategoryConfig $layerCategoryConfig,
        \Amasty\Shopby\Helper\FilterSetting\Proxy $filterSettingHelper,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\App\Request\Http $request,
        \Magento\Framework\Registry $registry,
        array $filters = [],
        $place = self::PLACE_SIDEBAR
    ) {
        $this->currentPlace = $place;
        $this->filterSetting = $filterSettingHelper;
        $this->scopeConfig = $scopeConfig;
        $this->request = $request;
        $this->registry = $registry;
        parent::__construct($objectManager, $filterableAttributes, $layerCategoryConfig, $filters);
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.