4

I had tried to compile the magento with this command sudo php bin/magento setup:di:compile when compiling process i had an error on one module as below

Errors during compilation: Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid\Collection Incompatible argument type: Required type: \Magento\Framework\DB\Adapter\AdapterInterface. Actual type: \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid\connection; File: /var/www/times/app/code/Smartwave/Dailydeals/Model/ResourceModel/Dailydeal/Grid/Collection.php

my collection.php file is below,

    <?php
    namespace Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Grid;

    class Collection extends 
    \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Collection implements 
    \Magento\Framework\Api\Search\SearchResultInterface
    {
    /**
     * Aggregations
     *
     * @var \Magento\Framework\Search\AggregationInterface
     */
    protected $aggregations;

    /**
     * constructor
     *
     * @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 $mainTable
     * @param $eventPrefix
     * @param $eventObject
     * @param $resourceModel
     * @param $model
     * @param $connection
     * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
     */
    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,
        $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, $connection, $resource);
        $this->_eventPrefix = $eventPrefix;
        $this->_eventObject = $eventObject;
        $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;
    }
}

And my Smartwave/Dailydeals/Model/ResourceModel/Dailydeal/collection file is below,

 <?php
 namespace Smartwave\Dailydeals\Model\ResourceModel\Dailydeal;

 class Collection extends 
 \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
 {
/**
 * ID Field Name
 *
 * @var string
 */
protected $_idFieldName = 'dailydeal_id';

/**
 * Event prefix
 *
 * @var string
 */
protected $_eventPrefix = 'sw_dailydeals_dailydeal_collection';

/**
 * Event object
 *
 * @var string
 */
protected $_eventObject = 'dailydeal_collection';

/**
 * Define resource model
 *
 * @return void
 */
protected function _construct()
{
    $this->_init('Smartwave\Dailydeals\Model\Dailydeal', 'Smartwave\Dailydeals\Model\ResourceModel\Dailydeal');
}

/**
 * Get SQL for get record count.
 * Extra GROUP BY strip added.
 *
 * @return \Magento\Framework\DB\Select
 */
public function getSelectCountSql()
{
    $countSelect = parent::getSelectCountSql();
    $countSelect->reset(\Zend_Db_Select::GROUP);
    return $countSelect;
}
/**
 * @param string $valueField
 * @param string $labelField
 * @param array $additional
 * @return array
 */
protected function _toOptionArray($valueField = 'dailydeal_id', $labelField = 'sw_product_sku', $additional = [])
{
    return parent::_toOptionArray($valueField, $labelField, $additional);
}
}
  • can you please share code \Smartwave\Dailydeals\Model\ResourceModel\Dailydeal\Collection file? – Abdul Jul 4 '18 at 9:14
  • i had added the file.. @Abdul – Ask Bytes Jul 4 '18 at 9:43
11

I had solved the error by replacing the $connection = null, with \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, within the constructor.

Thank guys for those who are tried to helping me. :)

  • 4
    Have you contacted Smartwave about this yet? This error still exists even in the newest versions of their themes (e.g. "porto"). – fritzmg Nov 8 '18 at 14:05
  • I had not contacted them. I solved by myself. this may be a bug on their theme. – Ask Bytes Nov 10 '18 at 6:39
  • How to override this, once I override this using di.xml then again I am getting same error as earlier. – groy Mar 5 at 11:57
  • @groy you may don't need to override. since it is a theme file and it is not a magento core, just make a above change directly to the collection file. – Ask Bytes Mar 6 at 13:27

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.