I have a custom shipping module in which I am trying to instantiate FedEx carrier class to use its method as seen in the code below. But this throws an error:
Exception #0 (MagentoFrameworkExceptionRuntimeException): Type Error occurred when creating object: PerfectmakeupmirrorsCustomShippingModelCarrierCustomshipping, Argument 7 passed to PerfectmakeupmirrorsCustomShippingModelCarrierCustomshipping::__construct() must be an instance of MagentoFedexModelCarrier, array given, called in /home/magento/web/magento2.perfectmakeupmirrors.com/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
I don’t seem to find what is wrong with the way I am trying to call the method of FedEx.
namespace PerfectmakeupmirrorsCustomShippingModelCarrier;
use MagentoQuoteModelQuoteAddressRateRequest;
use MagentoShippingModelCarrierAbstractCarrier;
use MagentoShippingModelCarrierCarrierInterface;
use MagentoFedexModelCarrier;
/**
* Custom shipping model
*/
class Customshipping extends AbstractCarrier implements CarrierInterface
{
const SHIPPING_STANDARD = 'STD';
const SHIPPING_2ND_DAY = '2DY';
const SHIPPING_OVERNIGHT = 'ON';
protected $_shipping_mode_strings = array(
self::SHIPPING_STANDARD => 'Standard Ground',
self::SHIPPING_2ND_DAY => 'Second Day',
self::SHIPPING_OVERNIGHT => 'Next Day Air',
);
/**
* @var string
*/
protected $_code = 'customshipping';
/**
* @var bool
*/
protected $_isFixed = true;
/**
* @var MagentoShippingModelRateResultFactory
*/
private $rateResultFactory;
/**
* @var MagentoQuoteModelQuoteAddressRateResultMethodFactory
*/
private $rateMethodFactory;
/**
* @var PerfectmakeupmirrorsCustomShippingHelperData
*/
private $helper;
/**
* @var PsrLogLoggerInterface
*/
protected $_logger;
private $carrierFedex;
/**
* @param MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig
* @param MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory
* @param PsrLogLoggerInterface $logger
* @param MagentoShippingModelRateResultFactory $rateResultFactory
* @param MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
MagentoQuoteModelQuoteAddressRateResultErrorFactory $rateErrorFactory,
PsrLogLoggerInterface $logger,
MagentoShippingModelRateResultFactory $rateResultFactory,
MagentoQuoteModelQuoteAddressRateResultMethodFactory $rateMethodFactory,
PerfectmakeupmirrorsCustomShippingHelperData $helper,
MagentoFedexModelCarrier $carrierFedex,
array $data = []
) {
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
$this->rateResultFactory = $rateResultFactory;
$this->rateMethodFactory = $rateMethodFactory;
$this->carrierFedex = $carrierFedex;
$this->_logger = $logger;
$this->helper = $helper;
}
/**
* Custom Shipping Rates Collector
*
* @param RateRequest $request
* @return MagentoShippingModelRateResult|bool
*/
public function collectRates(RateRequest $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$this->_logger->debug("Before FedEx call");
$fedex_rate = $this->carrierFedex->collectRates($request);
$this->_logger->debug("Fedex Rate " . $fedex_rate);
/** @var MagentoShippingModelRateResult $result */
$result = $this->rateResultFactory->create();