SaveShippingMethod.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Paypal\Controller\Express\AbstractExpress;
  8. class SaveShippingMethod extends \Magento\Paypal\Controller\Express\AbstractExpress
  9. {
  10. /**
  11. * Update shipping method (combined action for ajax and regular request)
  12. *
  13. * @return void
  14. */
  15. public function execute()
  16. {
  17. try {
  18. $isAjax = $this->getRequest()->getParam('isAjax');
  19. $this->_initCheckout();
  20. $this->_checkout->updateShippingMethod($this->getRequest()->getParam('shipping_method'));
  21. if ($isAjax) {
  22. $this->_view->loadLayout('paypal_express_review_details', true, true, false);
  23. $this->getResponse()->setBody(
  24. $this->_view->getLayout()->getBlock('page.block')->setQuote($this->_getQuote())->toHtml()
  25. );
  26. return;
  27. }
  28. } catch (\Magento\Framework\Exception\LocalizedException $e) {
  29. $this->messageManager->addExceptionMessage(
  30. $e,
  31. $e->getMessage()
  32. );
  33. } catch (\Exception $e) {
  34. $this->messageManager->addExceptionMessage(
  35. $e,
  36. __('We can\'t update shipping method.')
  37. );
  38. }
  39. if ($isAjax) {
  40. $this->getResponse()->setBody(
  41. '<script>window.location.href = '
  42. . $this->_url->getUrl('*/*/review')
  43. . ';</script>'
  44. );
  45. } else {
  46. $this->_redirect('*/*/review');
  47. }
  48. }
  49. }