Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SaveShippingMethod.php
Go to the documentation of this file.
1 <?php
7 
14 
19 {
23  private $shippingMethodUpdater;
24 
33  public function __construct(
34  Context $context,
37  ShippingMethodUpdater $shippingMethodUpdater
38  ) {
39  parent::__construct($context, $config, $checkoutSession);
40  $this->shippingMethodUpdater = $shippingMethodUpdater;
41  }
42 
46  public function execute()
47  {
48  $isAjax = $this->getRequest()->getParam('isAjax');
49  $quote = $this->checkoutSession->getQuote();
50 
51  try {
52  $this->validateQuote($quote);
53 
54  $this->shippingMethodUpdater->execute(
55  $this->getRequest()->getParam('shipping_method'),
56  $quote
57  );
58 
59  if ($isAjax) {
61  $response = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
62  $layout = $response->addHandle('paypal_express_review_details')->getLayout();
63 
64  $response = $layout->getBlock('page.block')->toHtml();
65  $this->getResponse()->setBody($response);
66 
67  return;
68  }
69  } catch (\Exception $e) {
70  $this->messageManager->addExceptionMessage($e, $e->getMessage());
71  }
72 
73  $path = $this->_url->getUrl('*/*/review', ['_secure' => true]);
74 
75  if ($isAjax) {
76  $this->getResponse()->setBody(sprintf('<script>window.location.href = "%s";</script>', $path));
77 
78  return;
79  }
80 
81  $this->_redirect($path);
82  }
83 }
$response
Definition: 404.php:11
_redirect($path, $arguments=[])
Definition: Action.php:167
$quote
__construct(Context $context, Config $config, Session $checkoutSession, ShippingMethodUpdater $shippingMethodUpdater)