0

Environment:

Magneto EE 2.3.4 PHP 7.2.23-1 OS Ubuntu 16.04

Error:

Type Error occurred when creating object: Custom\Module\Model\ResourceModel\Module\Grid\Collection\Interceptor

Situation:

I am trying to add and admin Grid in Magento 2 Custom Module... It's working fine on Developer Mode but I am getting this error in Production Mode

Here is My Code Of Custom\Module\Model\ResourceModel\Module\Grid\Collection.php

<?PHP
use Custom\Module\Model\ResourceModel\Module\Collection as CustomCollection;

/**
 * Class Grid COllection
 */

class Collection extends CustomCollection implements \Magento\Framework\Api\Search\SearchResultInterface
{
    private $_aggregations;

    private $storeManager;



    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,
        $mainTable,
        $eventPrefix,
        $eventObject,
        $resourceModel,
        $model = 'Magento\Framework\View\Element\UiComponent\DataProvider\Document',
        $connection = null,
        \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
    ) {
        parent::__construct(
            $entityFactory, 
            $logger, 
            $fetchStrategy, 
            $eventManager, 
            $storeManager, 
            $connection, 
            $resource
        );
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $this->storeManager = $storeManager;
        $this->_init($model, $resourceModel);
        $this->setMainTable($mainTable);
    }
    /**
     * @return \Magento\Framework\Search\AggregationInterface
     */
    public function getAggregations()
    {
        return $this->_aggregations;
    }

    /**
     * @param \Magento\Framework\Search\AggregationInterface $aggregations
     * @return $this
     */
    public function setAggregations($aggregations)
    {
        $this->_aggregations = $aggregations;
    }

    /**
     * Retrieve all ids for collection
     * Backward compatibility with EAV collection
     *
     * @param int $limit
     * @param int $offset
     * @return array
     */
    public function getAllIds($limit = null, $offset = null)
    {
        return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
    }

    /**
     * Get search criteria.
     *
     * @return \Magento\Framework\Api\SearchCriteriaInterface|null
     */
    public function getSearchCriteria()
    {
        return null;
    }

    /**
     * Set search criteria.
     *
     * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
    {
        return $this;
    }

    /**
     * Get total count.
     *
     * @return int
     */
    public function getTotalCount()
    {
        return $this->getSize();
    }

    /**
     * Set total count.
     *
     * @param int $totalCount
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setTotalCount($totalCount)
    {
        return $this;
    }

    /**
     * Set items list.
     *
     * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
     * @return $this
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
     */
    public function setItems(array $items = null)
    {
        return $this;
    }
}

I have Tried by removing var/ and generated/ folder and run php bin/magento setup:di:compile

  • Did you get the answer? Why it is happening in 'developer' mode? – Ahsan Horani Jun 22 at 12:59
  • Yes I have inherited Collection from CustomCollection but in my CustomCollection there was no any object as StoreManagerInterface so I removed in injected StoreManagerInterface class from Collection constructor and my issue was resolved – User 69 Jun 22 at 13:03
  • I am able to resolve my problem as well. But I am looking for answer on why it worked on 'developer' mode and why not worked in 'production' mode? Is it related to code compilation? – Ahsan Horani Jun 22 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.