0

I am using magento2.4.1 on php 7.3 I am facing this error right now.

Type Error occurred when creating object: 

Vendor\Module\Model\ResourceModel\PushNotification\Grid\Collection\Interceptor, Argument 5 passed to Ens\PushNotification\Model\ResourceModel\PushNotification\Grid\Collection\Interceptor::__construct() must implement interface Magento\Store\Model\StoreManagerInterface, string given, called in /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
Exception in /var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:131

And here is my code in app/code/Vendor/Module/Model/ResourceModel/PushNotification/Grid/Collection.php

<?php

namespace Ens\PushNotification\Model\ResourceModel\PushNotification\Grid;

use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
use Ens\PushNotification\Model\ResourceModel\PushNotification\Collection as PushNotificationCollection;

/**
 * Class Collection
 * Collection for displaying grid of sales documents
 */
class Collection extends PushNotificationCollection implements SearchResultInterface
{
    /**
     * @var AggregationInterface
     */
    protected $aggregations;

    /**
     * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
     * @param \Psr\Log\LoggerInterface $logger
     * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
     * @param \Magento\Framework\Event\ManagerInterface $eventManager
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
     * @param mixed|null $mainTable
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $eventPrefix
     * @param mixed $eventObject
     * @param mixed $resourceModel
     * @param string $model
     * @param null $connection
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb|null $resource
     *
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
     */
    public function __construct(
        \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
        \Psr\Log\LoggerInterface $logger,
        \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
        \Magento\Framework\Event\ManagerInterface $eventManager,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Framework\EntityManager\MetadataPool $metadataPool,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        \Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct(
            $entityFactory,
            $logger,
            $fetchStrategy,
            $eventManager,
            $connection,
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }

    /**
     * @return AggregationInterface
     */
    public function getAggregations()
    {
        return $this->aggregations;
    }

Do you have any idea why i am getting this error?

5
  • 1
    In your parent::__construct add $storeManager after $eventManager. Commented May 31, 2021 at 10:46
  • I did not worked. Commented May 31, 2021 at 11:00
  • 1
    Recompile, this issue shows up when you have a previously compiled interceptor with different construct arguments. Or set your environment to developer mode.
    – David Tay
    Commented May 31, 2021 at 13:52
  • Issue fixed. Thank you @RahulBarot for reply. i removed these two lines and problem get fixed. (1)\Magento\Store\Model\StoreManagerInterface $storeManager, (2) \Magento\Framework\EntityManager\MetadataPool $metadataPool, Commented Jun 1, 2021 at 4:54
  • 1
    Good to hear. Whenever you are extending a class and defining constructor you need to pass all arguments to parent constructor. Commented Jun 1, 2021 at 5:49

1 Answer 1

2

Try to run php bin/magento setup:di:compile command and check.

when we add new dependencies in constructor and without run di:compile command in frontend we face this type of similar issue.

please run command and fix issue if found.

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.