2

I have compilation issue in my module. While I am running command php bin/magento setup:di:compile facing this issue in magento 2.1.8. It's showing this error:

Incompatible argument type: Required type: \Magento\Framework\Data\Collection\AbstractDb. Actual type: \Magento\Framework\Model\ResourceModel\AbstractResource;

Here is my file:

<?php
namespace Namespace\Mkt\Model;

use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\ObjectManagerInterface;

/**
 * Fancyfeedbacktab fancyfeedback model
 */
class Orderapi extends \Magento\Framework\Model\AbstractModel     
{
    /**
     * @param \Magento\Framework\Model\Context $context
     * @param \Magento\Framework\Registry $registry
     * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
     * @param \Magento\Framework\Data\Collection\Db $resourceCollection
     * @param array $data
     */

    public $scopeConfig;

    public function __construct(
        \Magento\Framework\Model\Context $context,
        \Magento\Framework\Registry $registry,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
        \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
        array $data = []
    ) {
        $this->scopeConfig = $scopeConfig;
        $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
        $this->host=$this->scopeConfig->getValue(self::XML_PATH_HOST_KEY, $storeScope);
        $this->clientId=$this->scopeConfig->getValue(self::XML_PATH_CLIENT_ID, $storeScope);
        $this->clientSecret=$this->scopeConfig->getValue(self::XML_PATH_SECRET_KEY, $storeScope);
        //parent::__construct($context, $registry, $ScopeInterface, $resource, $resourceCollection, $data);
    }
}
1

Try this function -

use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\Context;
use Magento\Framework\Model\ResourceModel\AbstractResource;
use Magento\Framework\Registry;
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\Collection as CreditmemoCollection;
use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection;
use Magento\Sales\Model\ResourceModel\Order\Payment\Transaction\Collection as TransactionCollection;
use Magento\Sales\Model\ResourceModel\Order\Shipment\Collection as ShipmentCollection;


class Orderapi extends AbstractModel
{
    /**
     * @var ProductMetadataInterface
     */
    protected $_appProductMetadataInterface;

    /**
     * @var Resource
     */
    protected $_modelResource;

    /**
     * @var ManagerInterface
     */
    protected $_messageManagerInterface;

    /**
     * @var Collection
     */
    protected $_invoiceCollection;

    /**
     * @var ShipmentCollection
     */
    protected $_shipmentCollection;
    /**
     * @var CreditmemoCollection
     */
    protected $_creditmemoCollection;
    /**
     * @var TransactionCollection
     */
    protected $_transactionCollection;

    public function __construct(Context $context, 
        Registry $registry, 
        ProductMetadataInterface $appProductMetadataInterface, 
        \Magento\Framework\App\ResourceConnection $modelResource, 
        ManagerInterface $messageManagerInterface, 
        Collection $invoiceCollection, 
        ShipmentCollection $shipmentCollection, 
        CreditmemoCollection $creditmemoCollection,  
        TransactionCollection $transactionCollection, 
        AbstractResource $resource = null, 
        AbstractDb $resourceCollection = null, 
        array $data = [])
    {
        $this->_appProductMetadataInterface = $appProductMetadataInterface;
        $this->_modelResource = $modelResource;
        $this->_messageManagerInterface = $messageManagerInterface;
        $this->_invoiceCollection = $invoiceCollection;
        $this->_shipmentCollection = $shipmentCollection;
        $this->_creditmemoCollection = $creditmemoCollection;
        $this->_transactionCollection = $transactionCollection;

        parent::__construct($context, $registry, $resource, $resourceCollection, $data);
    }
  • Incompatible argument type: Required type: array. Actual type: \Magento\Framework\Data\Collection\AbstractDb getting this error now – Pankaj Sharma Sep 14 '18 at 7:00
  • Are you using these 2 dependencies that you injected in constructor? – Gagan Sep 14 '18 at 7:02
  • And delete var/generation folder and retry – Gagan Sep 14 '18 at 7:04
  • I deleted var/generation. but its not working – Pankaj Sharma Sep 14 '18 at 7:58
  • I have updated the answer and this is a working Model – Gagan Sep 14 '18 at 8:04

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.