Skip to content

Commit 82ce9bd

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MC-13775
2 parents 1cbd039 + a08dd4e commit 82ce9bd

File tree

13 files changed

+57
-222
lines changed

13 files changed

+57
-222
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/cc-form.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ define(
7979
*/
8080
onError: function (response) {
8181
braintree.showError($t('Payment ' + this.getTitle() + ' can\'t be initialized'));
82+
this.isPlaceOrderActionAllowed(true);
8283
throw response.message;
8384
},
8485

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/hosted-fields.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ define([
156156
*/
157157
placeOrderClick: function () {
158158
if (this.validateCardType()) {
159+
this.isPlaceOrderActionAllowed(false);
159160
$(this.getSelector('submit')).trigger('click');
160161
}
161162
},

app/code/Magento/Checkout/view/frontend/web/js/view/payment/default.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,22 @@ define([
133133
event.preventDefault();
134134
}
135135

136-
if (this.validate() &&
137-
additionalValidators.validate() &&
138-
this.isPlaceOrderActionAllowed() === true
139-
) {
136+
if (this.validate() && additionalValidators.validate()) {
140137
this.isPlaceOrderActionAllowed(false);
141138

142139
this.getPlaceOrderDeferredObject()
143-
.done(
140+
.fail(
141+
function () {
142+
self.isPlaceOrderActionAllowed(true);
143+
}
144+
).done(
144145
function () {
145146
self.afterPlaceOrder();
146147

147148
if (self.redirectAfterPlaceOrder) {
148149
redirectOnSuccessAction.execute();
149150
}
150151
}
151-
).always(
152-
function () {
153-
self.isPlaceOrderActionAllowed(true);
154-
}
155152
);
156153

157154
return true;

app/code/Magento/Payment/view/frontend/web/js/view/payment/iframe.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,8 @@ define([
114114
* @override
115115
*/
116116
placeOrder: function () {
117-
var self = this;
117+
if (this.validateHandler() && additionalValidators.validate()) {
118118

119-
if (this.validateHandler() &&
120-
additionalValidators.validate() &&
121-
this.isPlaceOrderActionAllowed() === true
122-
) {
123119
fullScreenLoader.startLoader();
124120

125121
this.isPlaceOrderActionAllowed(false);
@@ -131,15 +127,8 @@ define([
131127
method: this.getCode()
132128
}
133129
)
134-
).done(
135-
this.done.bind(this)
136-
).fail(
137-
this.fail.bind(this)
138-
).always(
139-
function () {
140-
self.isPlaceOrderActionAllowed(true);
141-
}
142-
);
130+
).done(this.done.bind(this))
131+
.fail(this.fail.bind(this));
143132

144133
this.initTimeoutHandler();
145134
}
@@ -203,6 +192,7 @@ define([
203192
*/
204193
fail: function () {
205194
fullScreenLoader.stopLoader();
195+
this.isPlaceOrderActionAllowed(true);
206196

207197
return this;
208198
},

app/code/Magento/Paypal/view/frontend/web/js/view/payment/method-renderer/payflowpro-method.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ define([
7979
placeOrder: function () {
8080
var self = this;
8181

82-
if (this.validateHandler() &&
83-
additionalValidators.validate() &&
84-
this.isPlaceOrderActionAllowed() === true
85-
) {
82+
if (this.validateHandler() && additionalValidators.validate()) {
8683
this.isPlaceOrderActionAllowed(false);
8784
fullScreenLoader.startLoader();
8885
$.when(

app/code/Magento/Quote/Model/QuoteManagement.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
3737
protected $eventManager;
3838

3939
/**
40-
* @var SubmitQuoteValidator
40+
* @var QuoteValidator
4141
*/
42-
private $submitQuoteValidator;
42+
protected $quoteValidator;
4343

4444
/**
4545
* @var OrderFactory
@@ -148,7 +148,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
148148

149149
/**
150150
* @param EventManager $eventManager
151-
* @param SubmitQuoteValidator $submitQuoteValidator
151+
* @param QuoteValidator $quoteValidator
152152
* @param OrderFactory $orderFactory
153153
* @param OrderManagement $orderManagement
154154
* @param CustomerManagement $customerManagement
@@ -173,7 +173,7 @@ class QuoteManagement implements \Magento\Quote\Api\CartManagementInterface
173173
*/
174174
public function __construct(
175175
EventManager $eventManager,
176-
SubmitQuoteValidator $submitQuoteValidator,
176+
QuoteValidator $quoteValidator,
177177
OrderFactory $orderFactory,
178178
OrderManagement $orderManagement,
179179
CustomerManagement $customerManagement,
@@ -196,7 +196,7 @@ public function __construct(
196196
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository = null
197197
) {
198198
$this->eventManager = $eventManager;
199-
$this->submitQuoteValidator = $submitQuoteValidator;
199+
$this->quoteValidator = $quoteValidator;
200200
$this->orderFactory = $orderFactory;
201201
$this->orderManagement = $orderManagement;
202202
$this->customerManagement = $customerManagement;
@@ -282,7 +282,6 @@ public function assignCustomer($cartId, $customerId, $storeId)
282282
throw new StateException(
283283
__('Cannot assign customer to the given cart. Customer already has active cart.')
284284
);
285-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
286285
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
287286
}
288287

@@ -455,7 +454,7 @@ protected function resolveItems(QuoteEntity $quote)
455454
protected function submitQuote(QuoteEntity $quote, $orderData = [])
456455
{
457456
$order = $this->orderFactory->create();
458-
$this->submitQuoteValidator->validateQuote($quote);
457+
$this->quoteValidator->validateBeforeSubmit($quote);
459458
if (!$quote->getCustomerIsGuest()) {
460459
if ($quote->getCustomerId()) {
461460
$this->_prepareCustomerQuote($quote);
@@ -510,7 +509,6 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
510509
$order->setCustomerFirstname($quote->getCustomerFirstname());
511510
$order->setCustomerMiddlename($quote->getCustomerMiddlename());
512511
$order->setCustomerLastname($quote->getCustomerLastname());
513-
$this->submitQuoteValidator->validateOrder($order);
514512

515513
$this->eventManager->dispatch(
516514
'sales_model_service_quote_submit_before',
@@ -627,13 +625,12 @@ private function rollbackAddresses(
627625
'exception' => $e,
628626
]
629627
);
630-
// phpcs:ignore Magento2.Exceptions.ThrowCatch
631628
} catch (\Exception $consecutiveException) {
632629
$message = sprintf(
633630
"An exception occurred on 'sales_model_service_quote_submit_failure' event: %s",
634631
$consecutiveException->getMessage()
635632
);
636-
// phpcs:ignore Magento2.Exceptions.DirectThrow
633+
637634
throw new \Exception($message, 0, $e);
638635
}
639636
}

app/code/Magento/Quote/Model/SubmitQuoteValidator.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

app/code/Magento/Quote/Test/Unit/Model/QuoteManagementTest.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
/**
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1515
* @SuppressWarnings(PHPMD.TooManyFields)
16-
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
17-
* @SuppressWarnings(PHPMD.ExcessiveClassLength)
1816
*/
1917
class QuoteManagementTest extends \PHPUnit\Framework\TestCase
2018
{
@@ -24,9 +22,9 @@ class QuoteManagementTest extends \PHPUnit\Framework\TestCase
2422
protected $model;
2523

2624
/**
27-
* @var \Magento\Quote\Model\SubmitQuoteValidator|\PHPUnit_Framework_MockObject_MockObject
25+
* @var \Magento\Quote\Model\QuoteValidator|\PHPUnit_Framework_MockObject_MockObject
2826
*/
29-
protected $submitQuoteValidator;
27+
protected $quoteValidator;
3028

3129
/**
3230
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
@@ -145,7 +143,7 @@ protected function setUp()
145143
{
146144
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
147145

148-
$this->submitQuoteValidator = $this->createMock(\Magento\Quote\Model\SubmitQuoteValidator::class);
146+
$this->quoteValidator = $this->createMock(\Magento\Quote\Model\QuoteValidator::class);
149147
$this->eventManager = $this->getMockForAbstractClass(\Magento\Framework\Event\ManagerInterface::class);
150148
$this->orderFactory = $this->createPartialMock(
151149
\Magento\Sales\Api\Data\OrderInterfaceFactory::class,
@@ -212,7 +210,7 @@ protected function setUp()
212210
\Magento\Quote\Model\QuoteManagement::class,
213211
[
214212
'eventManager' => $this->eventManager,
215-
'submitQuoteValidator' => $this->submitQuoteValidator,
213+
'quoteValidator' => $this->quoteValidator,
216214
'orderFactory' => $this->orderFactory,
217215
'orderManagement' => $this->orderManagement,
218216
'customerManagement' => $this->customerManagement,
@@ -562,9 +560,7 @@ public function testSubmit()
562560
$shippingAddress
563561
);
564562

565-
$this->submitQuoteValidator->expects($this->once())
566-
->method('validateQuote')
567-
->with($quote);
563+
$this->quoteValidator->expects($this->once())->method('validateBeforeSubmit')->with($quote);
568564
$this->quoteAddressToOrder->expects($this->once())
569565
->method('convert')
570566
->with($shippingAddress, $orderData)
@@ -659,7 +655,7 @@ public function testPlaceOrderIfCustomerIsGuest()
659655
->setConstructorArgs(
660656
[
661657
'eventManager' => $this->eventManager,
662-
'quoteValidator' => $this->submitQuoteValidator,
658+
'quoteValidator' => $this->quoteValidator,
663659
'orderFactory' => $this->orderFactory,
664660
'orderManagement' => $this->orderManagement,
665661
'customerManagement' => $this->customerManagement,
@@ -716,7 +712,7 @@ public function testPlaceOrder()
716712
->setConstructorArgs(
717713
[
718714
'eventManager' => $this->eventManager,
719-
'quoteValidator' => $this->submitQuoteValidator,
715+
'quoteValidator' => $this->quoteValidator,
720716
'orderFactory' => $this->orderFactory,
721717
'orderManagement' => $this->orderManagement,
722718
'customerManagement' => $this->customerManagement,
@@ -938,9 +934,6 @@ protected function prepareOrderFactory(
938934
return $order;
939935
}
940936

941-
/**
942-
* @throws NoSuchEntityException
943-
*/
944937
public function testGetCartForCustomer()
945938
{
946939
$customerId = 100;
@@ -985,9 +978,6 @@ protected function setPropertyValue(&$object, $property, $value)
985978
return $object;
986979
}
987980

988-
/**
989-
* @throws \Magento\Framework\Exception\LocalizedException
990-
*/
991981
public function testSubmitForCustomer()
992982
{
993983
$orderData = [];
@@ -1020,8 +1010,7 @@ public function testSubmitForCustomer()
10201010
$shippingAddress
10211011
);
10221012

1023-
$this->submitQuoteValidator->method('validateQuote')
1024-
->with($quote);
1013+
$this->quoteValidator->expects($this->once())->method('validateBeforeSubmit')->with($quote);
10251014
$this->quoteAddressToOrder->expects($this->once())
10261015
->method('convert')
10271016
->with($shippingAddress, $orderData)

0 commit comments

Comments
 (0)