shippingInformationManagement = $shippingInformationManagement; $this->quoteAddressResource = $quoteAddressResource; $this->quoteAddressFactory = $quoteAddressFactory; $this->shippingInformationFactory = $shippingInformationFactory; } /** * Sets shipping method for a specified shopping cart address * * @param Quote $cart * @param int $cartAddressId * @param string $carrierCode * @param string $methodCode * @throws GraphQlInputException * @throws GraphQlNoSuchEntityException */ public function execute(Quote $cart, int $cartAddressId, string $carrierCode, string $methodCode): void { $quoteAddress = $this->quoteAddressFactory->create(); $this->quoteAddressResource->load($quoteAddress, $cartAddressId); /** @var ShippingInformation $shippingInformation */ $shippingInformation = $this->shippingInformationFactory->create(); /* If the address is not a shipping address (but billing) the system will find the proper shipping address for the selected cart and set the information there (actual for single shipping address) */ $shippingInformation->setShippingAddress($quoteAddress); $shippingInformation->setShippingCarrierCode($carrierCode); $shippingInformation->setShippingMethodCode($methodCode); try { $this->shippingInformationManagement->saveAddressInformation($cart->getId(), $shippingInformation); } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException(__($exception->getMessage())); } catch (StateException $exception) { throw new GraphQlInputException(__($exception->getMessage())); } catch (InputException $exception) { throw new GraphQlInputException(__($exception->getMessage())); } } }