|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MagePrince |
|
5
|
|
|
* Copyright (C) 2020 Mageprince <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @package Mageprince_BuyNow |
|
8
|
|
|
* @copyright Copyright (c) 2020 Mageprince (http://www.mageprince.com/) |
|
9
|
|
|
* @license http://opensource.org/licenses/gpl-3.0.html GNU General Public License,version 3 (GPL-3.0) |
|
10
|
|
|
* @author MagePrince <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare (strict_types = 1); |
|
14
|
|
|
|
|
15
|
|
|
namespace Mageprince\BuyNow\Controller\Checkout; |
|
16
|
|
|
|
|
17
|
|
|
use Magento\Checkout\Api\AgreementsValidatorInterface; |
|
|
|
|
|
|
18
|
|
|
use Magento\Checkout\Api\Exception\PaymentProcessingRateLimitExceededException; |
|
|
|
|
|
|
19
|
|
|
use Magento\Checkout\Api\PaymentProcessingRateLimiterInterface; |
|
|
|
|
|
|
20
|
|
|
use Magento\Customer\Api\AccountManagementInterface; |
|
|
|
|
|
|
21
|
|
|
use Magento\Customer\Api\CustomerRepositoryInterface; |
|
|
|
|
|
|
22
|
|
|
use Magento\Customer\Model\Session; |
|
|
|
|
|
|
23
|
|
|
use Magento\Framework\App\Action\Context; |
|
|
|
|
|
|
24
|
|
|
use Magento\Framework\App\ObjectManager; |
|
|
|
|
|
|
25
|
|
|
use Magento\Framework\Data\Form\FormKey\Validator; |
|
|
|
|
|
|
26
|
|
|
use Magento\Framework\Exception\PaymentException; |
|
|
|
|
|
|
27
|
|
|
use Magento\Framework\Session\SessionManagerInterface; |
|
|
|
|
|
|
28
|
|
|
use Magento\Multishipping\Controller\Checkout; |
|
|
|
|
|
|
29
|
|
|
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State; |
|
|
|
|
|
|
30
|
|
|
use Psr\Log\LoggerInterface; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Placing orders. |
|
34
|
|
|
* |
|
35
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
36
|
|
|
*/ |
|
37
|
|
|
class OverviewPost extends \Magento\Multishipping\Controller\Checkout\OverviewPost |
|
|
|
|
|
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @var Validator |
|
41
|
|
|
* @deprecated Form key validation is handled on the framework level. |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $formKeyValidator; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var LoggerInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $logger; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var AgreementsValidatorInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $agreementsValidator; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var SessionManagerInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
private $session; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var PaymentProcessingRateLimiterInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
private $paymentRateLimiter; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param Context $context |
|
67
|
|
|
* @param Session $customerSession |
|
68
|
|
|
* @param CustomerRepositoryInterface $customerRepository |
|
69
|
|
|
* @param AccountManagementInterface $accountManagement |
|
70
|
|
|
* @param Validator $formKeyValidator |
|
71
|
|
|
* @param LoggerInterface $logger |
|
72
|
|
|
* @param AgreementsValidatorInterface $agreementValidator |
|
73
|
|
|
* @param SessionManagerInterface $session |
|
74
|
|
|
* @param PaymentProcessingRateLimiterInterface|null $paymentRateLimiter |
|
75
|
|
|
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory |
|
76
|
|
|
*/ |
|
77
|
|
|
public function __construct( |
|
78
|
|
|
Context $context, |
|
79
|
|
|
Session $customerSession, |
|
80
|
|
|
CustomerRepositoryInterface $customerRepository, |
|
81
|
|
|
AccountManagementInterface $accountManagement, |
|
82
|
|
|
Validator $formKeyValidator, |
|
83
|
|
|
LoggerInterface $logger, |
|
84
|
|
|
AgreementsValidatorInterface $agreementValidator, |
|
85
|
|
|
SessionManagerInterface $session, |
|
86
|
|
|
? PaymentProcessingRateLimiterInterface $paymentRateLimiter = null, |
|
87
|
|
|
\Magento\Quote\Model\QuoteFactory $quoteFactory |
|
|
|
|
|
|
88
|
|
|
) { |
|
89
|
|
|
$this->formKeyValidator = $formKeyValidator; |
|
|
|
|
|
|
90
|
|
|
$this->logger = $logger; |
|
91
|
|
|
$this->agreementsValidator = $agreementValidator; |
|
92
|
|
|
$this->session = $session; |
|
93
|
|
|
$this->paymentRateLimiter = $paymentRateLimiter ?? ObjectManager::getInstance()->get(PaymentProcessingRateLimiterInterface::class); |
|
94
|
|
|
$this->customerRepository = $customerRepository; |
|
|
|
|
|
|
95
|
|
|
$this->quoteFactory = $quoteFactory; |
|
|
|
|
|
|
96
|
|
|
parent::__construct( |
|
97
|
|
|
$context, |
|
98
|
|
|
$customerSession, |
|
99
|
|
|
$customerRepository, |
|
100
|
|
|
$accountManagement, |
|
101
|
|
|
$formKeyValidator, |
|
102
|
|
|
$logger, |
|
103
|
|
|
$agreementValidator, |
|
104
|
|
|
$session, |
|
105
|
|
|
$paymentRateLimiter |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Overview action |
|
111
|
|
|
* |
|
112
|
|
|
* @return void |
|
113
|
|
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
|
114
|
|
|
*/ |
|
115
|
|
|
public function execute() |
|
116
|
|
|
{ |
|
117
|
|
|
$currenctCart = $this->_getCheckout()->getQuote()->getId(); |
|
118
|
|
|
$buyNowId = $this->_getCheckout()->getQuote()->getBuyNowId(); |
|
119
|
|
|
$customerId = $this->_getCheckout()->getQuote()->getCustomerId(); |
|
120
|
|
|
try { |
|
121
|
|
|
$this->paymentRateLimiter->limit(); |
|
122
|
|
|
if (!$this->_validateMinimumAmount()) { |
|
123
|
|
|
return; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (!$this->agreementsValidator->isValid(array_keys($this->getRequest()->getPost('agreement', [])))) { |
|
127
|
|
|
$this->messageManager->addErrorMessage( |
|
128
|
|
|
__('Please agree to all Terms and Conditions before placing the order.') |
|
|
|
|
|
|
129
|
|
|
); |
|
130
|
|
|
$this->_redirect('*/*/billing'); |
|
131
|
|
|
return; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
$payment = $this->getRequest()->getPost('payment'); |
|
135
|
|
|
$paymentInstance = $this->_getCheckout()->getQuote()->getPayment(); |
|
136
|
|
|
if (isset($payment['cc_number'])) { |
|
137
|
|
|
$paymentInstance->setCcNumber($payment['cc_number']); |
|
138
|
|
|
} |
|
139
|
|
|
if (isset($payment['cc_cid'])) { |
|
140
|
|
|
$paymentInstance->setCcCid($payment['cc_cid']); |
|
141
|
|
|
} |
|
142
|
|
|
$this->_getCheckout()->createOrders(); |
|
143
|
|
|
$this->_getState()->setCompleteStep(State::STEP_OVERVIEW); |
|
144
|
|
|
|
|
145
|
|
|
if ($this->session->getAddressErrors()) { |
|
146
|
|
|
$this->_getState()->setActiveStep(State::STEP_RESULTS); |
|
147
|
|
|
$this->_redirect('*/*/results'); |
|
148
|
|
|
} else { |
|
149
|
|
|
$this->_getState()->setActiveStep(State::STEP_SUCCESS); |
|
150
|
|
|
$this->_getCheckout()->getCheckoutSession()->clearQuote(); |
|
151
|
|
|
$this->_getCheckout()->getCheckoutSession()->setDisplaySuccess(true); |
|
152
|
|
|
/* get buy now feture */ |
|
153
|
|
|
if (($customerId) && ($buyNowId)) { |
|
154
|
|
|
$customerRepoData = $this->customerRepository->getById($customerId); |
|
155
|
|
|
/* Update Currenct Cart */ |
|
156
|
|
|
if ($currenctCart) { |
|
157
|
|
|
$UpadateCurrenctCart = $this->quoteFactory->create(); |
|
158
|
|
|
$UpadateCurrenctCart->load($currenctCart); |
|
159
|
|
|
if ($UpadateCurrenctCart->hasData()) { |
|
160
|
|
|
$UpadateCurrenctCart->setBuyNowId(0); |
|
161
|
|
|
$UpadateCurrenctCart->setIsActive(0); |
|
162
|
|
|
$UpadateCurrenctCart->save(); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
/* Restore old Cart */ |
|
166
|
|
|
$quoteDataReplace = $this->quoteFactory->create(); |
|
167
|
|
|
$quoteDataReplace->load($buyNowId); |
|
168
|
|
|
if ($quoteDataReplace->hasData()) { |
|
169
|
|
|
$quoteDataReplace->assignCustomer($customerRepoData); |
|
170
|
|
|
$quoteDataReplace->setBuyNowId(0); |
|
171
|
|
|
$quoteDataReplace->setIsActive(1); |
|
172
|
|
|
$quoteDataReplace->save(); |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
$this->_redirect('*/*/success'); |
|
176
|
|
|
} |
|
177
|
|
|
} catch (PaymentProcessingRateLimitExceededException $ex) { |
|
178
|
|
|
$this->messageManager->addErrorMessage($ex->getMessage()); |
|
179
|
|
|
$this->_redirect('*/*/overview'); |
|
180
|
|
|
} catch (PaymentException $e) { |
|
181
|
|
|
$message = $e->getMessage(); |
|
182
|
|
|
if (!empty($message)) { |
|
183
|
|
|
$this->messageManager->addErrorMessage($message); |
|
184
|
|
|
} |
|
185
|
|
|
$this->_redirect('*/*/billing'); |
|
186
|
|
|
} catch (\Magento\Checkout\Exception $e) { |
|
|
|
|
|
|
187
|
|
|
$this->_objectManager->get( |
|
188
|
|
|
\Magento\Checkout\Helper\Data::class |
|
|
|
|
|
|
189
|
|
|
)->sendPaymentFailedEmail( |
|
190
|
|
|
$this->_getCheckout()->getQuote(), |
|
191
|
|
|
$e->getMessage(), |
|
192
|
|
|
'multi-shipping' |
|
193
|
|
|
); |
|
194
|
|
|
$this->_getCheckout()->getCheckoutSession()->clearQuote(); |
|
195
|
|
|
$this->messageManager->addErrorMessage($e->getMessage()); |
|
196
|
|
|
$this->_redirect('*/cart'); |
|
197
|
|
|
} catch (\Magento\Framework\Exception\LocalizedException $e) { |
|
|
|
|
|
|
198
|
|
|
$this->_objectManager->get( |
|
199
|
|
|
\Magento\Checkout\Helper\Data::class |
|
200
|
|
|
)->sendPaymentFailedEmail( |
|
201
|
|
|
$this->_getCheckout()->getQuote(), |
|
202
|
|
|
$e->getMessage(), |
|
203
|
|
|
'multi-shipping' |
|
204
|
|
|
); |
|
205
|
|
|
$this->messageManager->addErrorMessage($e->getMessage()); |
|
206
|
|
|
$this->_redirect('*/*/billing'); |
|
207
|
|
|
} catch (\Exception $e) { |
|
208
|
|
|
$this->logger->critical($e); |
|
209
|
|
|
try { |
|
210
|
|
|
$this->_objectManager->get( |
|
211
|
|
|
\Magento\Checkout\Helper\Data::class |
|
212
|
|
|
)->sendPaymentFailedEmail( |
|
213
|
|
|
$this->_getCheckout()->getQuote(), |
|
214
|
|
|
$e->getMessage(), |
|
215
|
|
|
'multi-shipping' |
|
216
|
|
|
); |
|
217
|
|
|
} catch (\Exception $e) { |
|
218
|
|
|
$this->logger->error($e->getMessage()); |
|
219
|
|
|
} |
|
220
|
|
|
$this->messageManager->addErrorMessage(__('Order place error')); |
|
221
|
|
|
$this->_redirect('*/*/billing'); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
} |
|
225
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths