config = $config; $this->quoteRepository = $quoteRepository; } /** * Execute operation * * @param string $shippingMethod * @param Quote $quote * @return void * @throws \InvalidArgumentException */ public function execute($shippingMethod, Quote $quote) { if (empty($shippingMethod)) { throw new \InvalidArgumentException('The "shippingMethod" field does not exists.'); } if (!$quote->getIsVirtual()) { $shippingAddress = $quote->getShippingAddress(); if ($shippingMethod !== $shippingAddress->getShippingMethod()) { $this->disabledQuoteAddressValidation($quote); $shippingAddress->setShippingMethod($shippingMethod); $shippingAddress->setCollectShippingRates(true); $quote->collectTotals(); $this->quoteRepository->save($quote); } } } }