![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/Ecombricks/InventoryQuote/Plugin/Model/Quote/ShippingAssignment/ |
<?php /** * Copyright © eComBricks. All rights reserved. * See COPYING.txt for license details. */ namespace Ecombricks\InventoryQuote\Plugin\Model\Quote\ShippingAssignment; /** * Quote shipping assignment shipping processor plugin */ class ShippingProcessor { /** * Shipping address management * * @var \Magento\Quote\Model\ShippingAddressManagement */ protected $shippingAddressManagement; /** * Shipping method management * * @var \Ecombricks\InventoryQuote\Model\ShippingMethodManagement */ protected $shippingMethodManagement; /** * Joint data * * @var \Ecombricks\InventoryQuote\Data\JointData */ protected $jointData; /** * Shipping method full code * * @var \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode */ protected $shippingMethodFullCode; /** * Constructor * * @param \Magento\Quote\Model\ShippingAddressManagement $shippingAddressManagement * @param \Ecombricks\InventoryQuote\Model\ShippingMethodManagement $shippingMethodManagement * @param \Ecombricks\InventoryQuote\Data\JointData $jointData * @param \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode $shippingMethodFullCode * @return void */ public function __construct( \Magento\Quote\Model\ShippingAddressManagement $shippingAddressManagement, \Ecombricks\InventoryQuote\Model\ShippingMethodManagement $shippingMethodManagement, \Ecombricks\InventoryQuote\Data\JointData $jointData, \Ecombricks\InventoryQuote\Data\ShippingMethodFullCode $shippingMethodFullCode ) { $this->shippingAddressManagement = $shippingAddressManagement; $this->shippingMethodManagement = $shippingMethodManagement; $this->jointData = $jointData; $this->shippingMethodFullCode = $shippingMethodFullCode; } /** * Save * * @param \Magento\Quote\Api\Data\ShippingInterface $shipping * @param \Magento\Quote\Api\Data\CartInterface $quote * @return void */ public function save(\Magento\Quote\Api\Data\ShippingInterface $shipping, \Magento\Quote\Api\Data\CartInterface $quote) { $shippingAddress = $shipping->getAddress(); $this->shippingAddressManagement->assign($quote->getId(), $shippingAddress); $shippingMethods = $shipping->getMethod(); if (empty($shippingMethods) || $quote->getItemsCount() <= 0) { return $this; } $shippingCarrierCodes = []; $shippingMethodCodes = []; foreach ($shippingMethods as $sourceCode => $shippingMethod) { list($shippingCarrierCode, $shippingMethodCode) = $this->shippingMethodFullCode->parse($shippingMethod); $shippingCarrierCodes[$sourceCode] = $shippingCarrierCode; $shippingMethodCodes[$sourceCode] = $shippingMethodCode; } $this->shippingMethodManagement->apply( $quote->getId(), $this->jointData->generate($shippingCarrierCodes), $this->jointData->generate($shippingMethodCodes) ); } /** * Around save * * @param \Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor $subject * @param \Closure $proceed * @param \Magento\Quote\Api\Data\ShippingInterface $shipping * @param \Magento\Quote\Api\Data\CartInterface $quote * @return void */ public function aroundSave( \Magento\Quote\Model\Quote\ShippingAssignment\ShippingProcessor $subject, \Closure $proceed, \Magento\Quote\Api\Data\ShippingInterface $shipping, \Magento\Quote\Api\Data\CartInterface $quote ) { return $this->save($shipping, $quote); } }