Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ShippingMethodUpdater.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  private $config;
21 
25  private $quoteRepository;
26 
33  public function __construct(
34  Config $config,
35  CartRepositoryInterface $quoteRepository
36  ) {
37  $this->config = $config;
38  $this->quoteRepository = $quoteRepository;
39  }
40 
49  public function execute($shippingMethod, Quote $quote)
50  {
51  if (empty($shippingMethod)) {
52  throw new \InvalidArgumentException('The "shippingMethod" field does not exists.');
53  }
54 
55  if (!$quote->getIsVirtual()) {
56  $shippingAddress = $quote->getShippingAddress();
57  if ($shippingMethod !== $shippingAddress->getShippingMethod()) {
58  $this->disabledQuoteAddressValidation($quote);
59 
60  $shippingAddress->setShippingMethod($shippingMethod);
61  $shippingAddress->setCollectShippingRates(true);
62 
63  $quote->collectTotals();
64 
65  $this->quoteRepository->save($quote);
66  }
67  }
68  }
69 }
$config
Definition: fraud_order.php:17
$quote
$shippingAddress
Definition: order.php:40
__construct(Config $config, CartRepositoryInterface $quoteRepository)
$quoteRepository
$shippingMethod
Definition: popup.phtml:12