I am trying to override multishipping.php file in vendor/magento/module-multishipping/Model/Checkout/Type/Multishipping.php
-
29-01-2021 - |
Question
so far I've experienced some complications performing this override, I had to override also PlaceOrderDefaulr, PlaceOrderFactory and PlaceOrderInferface
I've added preferences tags in ../etc/di.xml of my module to include above mentioned classes, but now the error prompted is:
Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Multishipping\Model\Checkout\Type\Multishipping::__construct() must be an instance of Magento\Checkout\Model\Session, array given, called in C:\xampp\htdocs\Magento2.2.5\app\code\Inchoo\Hello\Model\Checkout\Type\Multishipping.php on line 271 and defined in C:\xampp\htdocs\Magento2.2.5\vendor\magento\module-multishipping\Model\Checkout\Type\Multishipping.php:209 Stack trace: #0 C:\xampp\htdocs\Magento2.2.5\app\code\Inchoo\Hello\Model\Checkout\Type\Multishipping.php(271): Magento\Multishipping\Model\Checkout\Type\Multishipping->__construct(Array)
1 C:\xampp\htdocs\Magento2.2.5\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(111):
Inchoo\Hello\Model\Checkout\Type\Multishipping->__construct(Object(Magento\Checkout\Model\Session), Object(Magento\Customer\Model\Session), Object(Magento\Sales\Model\OrderFactory), Object(Magento\Customer\Model\ResourceModel\AddressRepository), Object(Magento\Framework\Event\Manager\Proxy), Object(Magento\Framework\A in C:\xampp\htdocs\Magento2.2.5\vendor\magento\module-multishipping\Model\Checkout\Type\Multishipping.php on line 209
Solution
Please change your cunstructor as i given below.
public function __construct(\Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Customer\Api\AddressRepositoryInterface $addressRepository, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Session\Generic $session, \Magento\Quote\Model\Quote\AddressFactory $addressFactory, \Magento\Quote\Model\Quote\Address\ToOrder $quoteAddressToOrder, \Magento\Quote\Model\Quote\Address\ToOrderAddress $quoteAddressToOrderAddress, \Magento\Quote\Model\Quote\Payment\ToOrderPayment $quotePaymentToOrderPayment, \Magento\Quote\Model\Quote\Item\ToOrderItem $quoteItemToOrderItem, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification, \Magento\Multishipping\Helper\Data $helper, \Magento\Sales\Model\Order\Email\Sender\OrderSender $orderSender, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Api\FilterBuilder $filterBuilder, \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector, array $data = array()) {
parent::__construct($checkoutSession, $customerSession, $orderFactory, $addressRepository, $eventManager, $scopeConfig, $session, $addressFactory, $quoteAddressToOrder, $quoteAddressToOrderAddress, $quotePaymentToOrderPayment, $quoteItemToOrderItem, $storeManager, $paymentSpecification, $helper, $orderSender, $priceCurrency, $quoteRepository, $searchCriteriaBuilder, $filterBuilder, $totalsCollector, $data);
}
check after that.
OTHER TIPS
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Customer\Model\Session $customerSession,
\Magento\Sales\Model\OrderFactory $orderFactory,
AddressRepositoryInterface $addressRepository,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Session\Generic $session,
\Magento\Quote\Model\Quote\AddressFactory $addressFactory,
\Magento\Quote\Model\Quote\Address\ToOrder $quoteAddressToOrder,
\Magento\Quote\Model\Quote\Address\ToOrderAddress $quoteAddressToOrderAddress,
\Magento\Quote\Model\Quote\Payment\ToOrderPayment $quotePaymentToOrderPayment,
\Magento\Quote\Model\Quote\Item\ToOrderItem $quoteItemToOrderItem,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Payment\Model\Method\SpecificationInterface $paymentSpecification,
\Magento\Multishipping\Helper\Data $helper,
OrderSender $orderSender,
PriceCurrencyInterface $priceCurrency,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder,
\Magento\Framework\Api\FilterBuilder $filterBuilder,
\Magento\Quote\Model\Quote\TotalsCollector $totalsCollector,
array $data = [],
\Magento\Quote\Api\Data\CartExtensionFactory $cartExtensionFactory = null,
AllowedCountries $allowedCountryReader = null,
Multishipping\PlaceOrderFactory $placeOrderFactory = null,
LoggerInterface $logger = null,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper = null
) {
$this->_eventManager = $eventManager;
$this->_scopeConfig = $scopeConfig;
$this->_session = $session;
$this->_addressFactory = $addressFactory;
$this->_storeManager = $storeManager;
$this->paymentSpecification = $paymentSpecification;
$this->helper = $helper;
$this->_checkoutSession = $checkoutSession;
$this->_customerSession = $customerSession;
$this->_orderFactory = $orderFactory;
$this->addressRepository = $addressRepository;
$this->orderSender = $orderSender;
$this->priceCurrency = $priceCurrency;
$this->quoteRepository = $quoteRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->filterBuilder = $filterBuilder;
$this->quoteAddressToOrder = $quoteAddressToOrder;
$this->quoteItemToOrderItem = $quoteItemToOrderItem;
$this->quotePaymentToOrderPayment = $quotePaymentToOrderPayment;
$this->quoteAddressToOrderAddress = $quoteAddressToOrderAddress;
$this->totalsCollector = $totalsCollector;
$this->cartExtensionFactory = $cartExtensionFactory ?: ObjectManager::getInstance()
->get(\Magento\Quote\Api\Data\CartExtensionFactory::class);
$this->allowedCountryReader = $allowedCountryReader ?: ObjectManager::getInstance()
->get(AllowedCountries::class);
$this->placeOrderFactory = $placeOrderFactory ?: ObjectManager::getInstance()
->get(Multishipping\PlaceOrderFactory::class);
$this->logger = $logger ?: ObjectManager::getInstance()
->get(LoggerInterface::class);
$this->dataObjectHelper = $dataObjectHelper ?: ObjectManager::getInstance()
->get(\Magento\Framework\Api\DataObjectHelper::class);
parent::__construct($data);
$this->_init();
}