|
3 | 3 | * Copyright © Magento, Inc. All rights reserved. |
4 | 4 | * See COPYING.txt for license details. |
5 | 5 | */ |
| 6 | + |
6 | 7 | namespace Magento\Sales\Controller\Adminhtml\Order\Create; |
7 | 8 |
|
| 9 | +use Magento\Framework\Controller\ResultFactory; |
8 | 10 | use Magento\Framework\Exception\PaymentException; |
9 | 11 |
|
10 | 12 | class Save extends \Magento\Sales\Controller\Adminhtml\Order\Create |
11 | 13 | { |
12 | 14 | /** |
13 | 15 | * Saving quote and create order |
14 | 16 | * |
15 | | - * @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect |
| 17 | + * @return \Magento\Framework\Controller\ResultInterface |
16 | 18 | * |
17 | 19 | * @SuppressWarnings(PHPMD.CyclomaticComplexity) |
18 | 20 | */ |
19 | 21 | public function execute() |
20 | 22 | { |
21 | | - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ |
22 | | - $resultRedirect = $this->resultRedirectFactory->create(); |
| 23 | + $path = 'sales/*/'; |
| 24 | + $pathParams = []; |
| 25 | + |
23 | 26 | try { |
24 | 27 | // check if the creation of a new customer is allowed |
25 | 28 | if (!$this->_authorization->isAllowed('Magento_Customer::manage') |
@@ -49,31 +52,30 @@ public function execute() |
49 | 52 | ->createOrder(); |
50 | 53 |
|
51 | 54 | $this->_getSession()->clearStorage(); |
52 | | - $this->messageManager->addSuccess(__('You created the order.')); |
| 55 | + $this->messageManager->addSuccessMessage(__('You created the order.')); |
53 | 56 | if ($this->_authorization->isAllowed('Magento_Sales::actions_view')) { |
54 | | - $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]); |
| 57 | + $pathParams = ['order_id' => $order->getId()]; |
| 58 | + $path = 'sales/order/view'; |
55 | 59 | } else { |
56 | | - $resultRedirect->setPath('sales/order/index'); |
| 60 | + $path = 'sales/order/index'; |
57 | 61 | } |
58 | 62 | } catch (PaymentException $e) { |
59 | 63 | $this->_getOrderCreateModel()->saveQuote(); |
60 | 64 | $message = $e->getMessage(); |
61 | 65 | if (!empty($message)) { |
62 | | - $this->messageManager->addError($message); |
| 66 | + $this->messageManager->addErrorMessage($message); |
63 | 67 | } |
64 | | - $resultRedirect->setPath('sales/*/'); |
65 | 68 | } catch (\Magento\Framework\Exception\LocalizedException $e) { |
66 | 69 | // customer can be created before place order flow is completed and should be stored in current session |
67 | | - $this->_getSession()->setCustomerId($this->_getSession()->getQuote()->getCustomerId()); |
| 70 | + $this->_getSession()->setCustomerId((int)$this->_getSession()->getQuote()->getCustomerId()); |
68 | 71 | $message = $e->getMessage(); |
69 | 72 | if (!empty($message)) { |
70 | | - $this->messageManager->addError($message); |
| 73 | + $this->messageManager->addErrorMessage($message); |
71 | 74 | } |
72 | | - $resultRedirect->setPath('sales/*/'); |
73 | 75 | } catch (\Exception $e) { |
74 | | - $this->messageManager->addException($e, __('Order saving error: %1', $e->getMessage())); |
75 | | - $resultRedirect->setPath('sales/*/'); |
| 76 | + $this->messageManager->addExceptionMessage($e, __('Order saving error: %1', $e->getMessage())); |
76 | 77 | } |
77 | | - return $resultRedirect; |
| 78 | + |
| 79 | + return $this->resultRedirectFactory->create()->setPath($path, $pathParams); |
78 | 80 | } |
79 | 81 | } |
0 commit comments