Skip to content

Commit 10f06c6

Browse files
committed
Merge pull request #266 from magento-mpi/MAGETWO-36037
[MPI] Bugs
2 parents 99dca3e + 7dc6ee9 commit 10f06c6

File tree

2 files changed

+371
-24
lines changed

2 files changed

+371
-24
lines changed

app/code/Magento/Checkout/Controller/Onepage/SaveOrder.php

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Checkout\Controller\Onepage;
77

8+
use Magento\Framework\Object;
89
use Magento\Framework\Exception\PaymentException;
910

1011
class SaveOrder extends \Magento\Checkout\Controller\Onepage
@@ -26,16 +27,17 @@ public function execute()
2627
return $this->_ajaxRedirectResponse();
2728
}
2829

29-
$result = [];
30+
$result = new Object();
3031
try {
3132
$agreementsValidator = $this->_objectManager->get('Magento\Checkout\Model\Agreements\AgreementsValidator');
3233
if (!$agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) {
33-
$result['success'] = false;
34-
$result['error'] = true;
35-
$result['error_messages'] = __(
36-
'Please agree to all the terms and conditions before placing the order.'
34+
$result->setData('success', false);
35+
$result->setData('error', true);
36+
$result->setData(
37+
'error_messages',
38+
__('Please agree to all the terms and conditions before placing the order.')
3739
);
38-
return $this->resultJsonFactory->create()->setData($result);
40+
return $this->resultJsonFactory->create()->setData($result->getData());
3941
}
4042

4143
$data = $this->getRequest()->getPost('payment', []);
@@ -54,55 +56,78 @@ public function execute()
5456
$this->getOnepage()->saveOrder();
5557

5658
$redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
57-
$result['success'] = true;
58-
$result['error'] = false;
59+
$result->setData('success', true);
60+
$result->setData('error', false);
5961
} catch (PaymentException $e) {
6062
$message = $e->getMessage();
6163
if (!empty($message)) {
62-
$result['error_messages'] = $message;
64+
$result->setData('error_messages', $message);
6365
}
64-
$result['goto_section'] = 'payment';
65-
$result['update_section'] = ['name' => 'payment-method', 'html' => $this->_getPaymentMethodsHtml()];
66+
$result->setData('goto_section', 'payment');
67+
$result->setData(
68+
'update_section',
69+
[
70+
'name' => 'payment-method',
71+
'html' => $this->_getPaymentMethodsHtml()
72+
]
73+
);
6674
} catch (\Magento\Framework\Exception\LocalizedException $e) {
6775
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
6876
$this->_objectManager->get('Magento\Checkout\Helper\Data')
6977
->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
70-
$result['success'] = false;
71-
$result['error'] = true;
72-
$result['error_messages'] = $e->getMessage();
78+
$result->setData(
79+
'success',
80+
false
81+
);
82+
$result->setData('error', true);
83+
$result->setData('error_messages', $e->getMessage());
7384
$gotoSection = $this->getOnepage()->getCheckout()->getGotoSection();
7485
if ($gotoSection) {
75-
$result['goto_section'] = $gotoSection;
86+
$result->setData('goto_section', $gotoSection);
7687
$this->getOnepage()->getCheckout()->setGotoSection(null);
7788
}
7889

7990
$updateSection = $this->getOnepage()->getCheckout()->getUpdateSection();
8091
if ($updateSection) {
8192
if (isset($this->_sectionUpdateFunctions[$updateSection])) {
8293
$updateSectionFunction = $this->_sectionUpdateFunctions[$updateSection];
83-
$result['update_section'] = [
84-
'name' => $updateSection,
85-
'html' => $this->{$updateSectionFunction}(),
86-
];
94+
$result->setData(
95+
'update_section',
96+
[
97+
'name' => $updateSection,
98+
'html' => $this->{$updateSectionFunction}(),
99+
]
100+
);
87101
}
88102
$this->getOnepage()->getCheckout()->setUpdateSection(null);
89103
}
90104
} catch (\Exception $e) {
91105
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
92106
$this->_objectManager->get('Magento\Checkout\Helper\Data')
93107
->sendPaymentFailedEmail($this->getOnepage()->getQuote(), $e->getMessage());
94-
$result['success'] = false;
95-
$result['error'] = true;
96-
$result['error_messages'] = __('Something went wrong processing your order. Please try again later.');
108+
$result->setData('success', false);
109+
$result->setData('error', true);
110+
$result->setData(
111+
'error_messages',
112+
__('Something went wrong processing your order. Please try again later.')
113+
);
97114
}
98115
/**
99116
* when there is redirect to third party, we don't want to save order yet.
100117
* we will save the order in return action.
101118
*/
102119
if (isset($redirectUrl)) {
103-
$result['redirect'] = $redirectUrl;
120+
$result->setData('redirect', $redirectUrl);
104121
}
105122

106-
return $this->resultJsonFactory->create()->setData($result);
123+
$this->_eventManager->dispatch(
124+
'checkout_controller_onepage_saveOrder',
125+
[
126+
'result' => $result,
127+
'action' => $this
128+
]
129+
);
130+
131+
return $this->resultJsonFactory->create()->setData($result->getData());
107132
}
108133
}

0 commit comments

Comments
 (0)