/
Save.php
77 lines (73 loc) · 3.36 KB
/
Save.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Controller\Adminhtml\Order\Create;
use Magento\Framework\Exception\PaymentException;
class Save extends \Magento\Sales\Controller\Adminhtml\Order\Create
{
/**
* Saving quote and create order
*
* @return \Magento\Backend\Model\View\Result\Forward|\Magento\Backend\Model\View\Result\Redirect
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function execute()
{
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
try {
// check if the creation of a new customer is allowed
if (!$this->_authorization->isAllowed('Magento_Customer::manage')
&& !$this->_getSession()->getCustomerId()
&& !$this->_getSession()->getQuote()->getCustomerIsGuest()
) {
return $this->resultForwardFactory->create()->forward('denied');
}
$this->_getOrderCreateModel()->getQuote()->setCustomerId($this->_getSession()->getCustomerId());
$this->_processActionData('save');
$paymentData = $this->getRequest()->getPost('payment');
if ($paymentData) {
$paymentData['checks'] = [
\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_INTERNAL,
\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY,
\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY,
\Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
\Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL,
];
$this->_getOrderCreateModel()->setPaymentData($paymentData);
$this->_getOrderCreateModel()->getQuote()->getPayment()->addData($paymentData);
}
$order = $this->_getOrderCreateModel()
->setIsValidate(true)
->importPostData($this->getRequest()->getPost('order'))
->createOrder();
$this->_getSession()->clearStorage();
$this->messageManager->addSuccess(__('You created the order.'));
if ($this->_authorization->isAllowed('Magento_Sales::actions_view')) {
$resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);
} else {
$resultRedirect->setPath('sales/order/index');
}
} catch (PaymentException $e) {
$this->_getOrderCreateModel()->saveQuote();
$message = $e->getMessage();
if (!empty($message)) {
$this->messageManager->addError($message);
}
$resultRedirect->setPath('sales/*/');
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$message = $e->getMessage();
if (!empty($message)) {
$this->messageManager->addError($message);
}
$resultRedirect->setPath('sales/*/');
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Order saving error: %1', $e->getMessage()));
$resultRedirect->setPath('sales/*/');
}
return $resultRedirect;
}
}