shippingFactory = $shippingFactory; $this->shippingAddressManagement = $shippingAddressManagement; $this->shippingMethodManagement = $shippingMethodManagement; } /** * @param \Magento\Quote\Api\Data\AddressInterface $shippingAddress * @return \Magento\Quote\Api\Data\ShippingInterface */ public function create(\Magento\Quote\Api\Data\AddressInterface $shippingAddress) { /** @var \Magento\Quote\Api\Data\ShippingInterface $shipping */ $shipping = $this->shippingFactory->create(); $shipping->setMethod($shippingAddress->getShippingMethod()); $shipping->setAddress($shippingAddress); return $shipping; } /** * @param ShippingInterface $shipping * @param CartInterface $quote * @return void */ public function save(ShippingInterface $shipping, CartInterface $quote) { $this->shippingAddressManagement->assign($quote->getId(), $shipping->getAddress()); if (!empty($shipping->getMethod()) && $quote->getItemsCount() > 0) { $nameComponents = explode('_', $shipping->getMethod()); $carrierCode = array_shift($nameComponents); // carrier method code can contains more one name component $methodCode = implode('_', $nameComponents); $this->shippingMethodManagement->apply($quote->getId(), $carrierCode, $methodCode); } } }