Skip to content

Commit 733f2fc

Browse files
authored
Merge pull request #3489 from magento-mpi/forwardport-1411
[MPI]-fix1411
2 parents b842b86 + 87a8bd5 commit 733f2fc

File tree

31 files changed

+738
-913
lines changed

31 files changed

+738
-913
lines changed

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

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
define([
88
'jquery',
99
'underscore',
10-
'mage/utils/wrapper',
1110
'Magento_Checkout/js/view/payment/default',
1211
'Magento_Braintree/js/view/payment/adapter',
1312
'Magento_Checkout/js/model/quote',
@@ -19,7 +18,6 @@ define([
1918
], function (
2019
$,
2120
_,
22-
wrapper,
2321
Component,
2422
Braintree,
2523
quote,
@@ -105,6 +103,12 @@ define([
105103
}
106104
});
107105

106+
quote.shippingAddress.subscribe(function () {
107+
if (self.isActive()) {
108+
self.reInitPayPal();
109+
}
110+
});
111+
108112
// for each component initialization need update property
109113
this.isReviewRequired(false);
110114
this.initClientConfig();
@@ -222,9 +226,8 @@ define([
222226

223227
/**
224228
* Re-init PayPal Auth Flow
225-
* @param {Function} callback - Optional callback
226229
*/
227-
reInitPayPal: function (callback) {
230+
reInitPayPal: function () {
228231
if (Braintree.checkout) {
229232
Braintree.checkout.teardown(function () {
230233
Braintree.checkout = null;
@@ -235,17 +238,6 @@ define([
235238
this.clientConfig.paypal.amount = this.grandTotalAmount;
236239
this.clientConfig.paypal.shippingAddressOverride = this.getShippingAddress();
237240

238-
if (callback) {
239-
this.clientConfig.onReady = wrapper.wrap(
240-
this.clientConfig.onReady,
241-
function (original, checkout) {
242-
this.clientConfig.onReady = original;
243-
original(checkout);
244-
callback();
245-
}.bind(this)
246-
);
247-
}
248-
249241
Braintree.setConfig(this.clientConfig);
250242
Braintree.setup();
251243
},
@@ -428,19 +420,17 @@ define([
428420
* Triggers when customer click "Continue to PayPal" button
429421
*/
430422
payWithPayPal: function () {
431-
this.reInitPayPal(function () {
432-
if (!additionalValidators.validate()) {
433-
return;
434-
}
423+
if (!additionalValidators.validate()) {
424+
return;
425+
}
435426

436-
try {
437-
Braintree.checkout.paypal.initAuthFlow();
438-
} catch (e) {
439-
this.messageContainer.addErrorMessage({
440-
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
441-
});
442-
}
443-
}.bind(this));
427+
try {
428+
Braintree.checkout.paypal.initAuthFlow();
429+
} catch (e) {
430+
this.messageContainer.addErrorMessage({
431+
message: $t('Payment ' + this.getTitle() + ' can\'t be initialized.')
432+
});
433+
}
444434
},
445435

446436
/**

app/code/Magento/Bundle/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@
143143
</argument>
144144
</arguments>
145145
</type>
146+
<type name="Magento\Sales\Model\Order\ProductOption">
147+
<arguments>
148+
<argument name="processorPool" xsi:type="array">
149+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
150+
</argument>
151+
</arguments>
152+
</type>
146153
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
147154
<arguments>
148155
<argument name="excludeAdjustments" xsi:type="array">

app/code/Magento/Captcha/Model/Customer/Plugin/AjaxLogin.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Captcha\Model\Customer\Plugin;
89

910
use Magento\Captcha\Helper\Data as CaptchaHelper;
10-
use Magento\Framework\Session\SessionManagerInterface;
11+
use Magento\Customer\Controller\Ajax\Login;
12+
use Magento\Framework\Controller\Result\Json;
1113
use Magento\Framework\Controller\Result\JsonFactory;
14+
use Magento\Framework\Session\SessionManagerInterface;
1215

16+
/**
17+
* The plugin for ajax login controller.
18+
*/
1319
class AjaxLogin
1420
{
1521
/**
@@ -61,14 +67,14 @@ public function __construct(
6167
}
6268

6369
/**
64-
* @param \Magento\Customer\Controller\Ajax\Login $subject
70+
* Validates captcha during request execution.
71+
*
72+
* @param Login $subject
6573
* @param \Closure $proceed
6674
* @return $this
67-
* @SuppressWarnings(PHPMD.NPathComplexity)
68-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6975
*/
7076
public function aroundExecute(
71-
\Magento\Customer\Controller\Ajax\Login $subject,
77+
Login $subject,
7278
\Closure $proceed
7379
) {
7480
$captchaFormIdField = 'captcha_form_id';
@@ -93,26 +99,31 @@ public function aroundExecute(
9399
foreach ($this->formIds as $formId) {
94100
if ($formId === $loginFormId) {
95101
$captchaModel = $this->helper->getCaptcha($formId);
102+
96103
if ($captchaModel->isRequired($username)) {
97-
$captchaModel->logAttempt($username);
98104
if (!$captchaModel->isCorrect($captchaString)) {
99105
$this->sessionManager->setUsername($username);
100-
return $this->returnJsonError(__('Incorrect CAPTCHA'));
106+
$captchaModel->logAttempt($username);
107+
return $this->returnJsonError(__('Incorrect CAPTCHA'), true);
101108
}
102109
}
110+
111+
$captchaModel->logAttempt($username);
103112
}
104113
}
105114
return $proceed();
106115
}
107116

108117
/**
118+
* Gets Json response.
109119
*
110120
* @param \Magento\Framework\Phrase $phrase
111-
* @return \Magento\Framework\Controller\Result\Json
121+
* @param bool $isCaptchaRequired
122+
* @return Json
112123
*/
113-
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
124+
private function returnJsonError(\Magento\Framework\Phrase $phrase, bool $isCaptchaRequired = false): Json
114125
{
115126
$resultJson = $this->resultJsonFactory->create();
116-
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
127+
return $resultJson->setData(['errors' => true, 'message' => $phrase, 'captcha' => $isCaptchaRequired]);
117128
}
118129
}

app/code/Magento/Captcha/Test/Unit/Model/Customer/Plugin/AjaxLoginTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function testAroundExecuteIncorrectCaptcha()
158158
$this->resultJsonMock
159159
->expects($this->once())
160160
->method('setData')
161-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
161+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA'), 'captcha' => true])
162162
->will($this->returnSelf());
163163

164164
$closure = function () {

app/code/Magento/Captcha/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
</arguments>
2828
</type>
2929
<type name="Magento\Customer\Controller\Ajax\Login">
30-
<plugin name="configurable_product" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
30+
<plugin name="captcha_validation" type="Magento\Captcha\Model\Customer\Plugin\AjaxLogin" sortOrder="50" />
3131
</type>
3232
<type name="Magento\Captcha\Model\Customer\Plugin\AjaxLogin">
3333
<arguments>

app/code/Magento/Captcha/view/frontend/web/js/model/captcha.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ define([
1717
imageSource: ko.observable(captchaData.imageSrc),
1818
visibility: ko.observable(false),
1919
captchaValue: ko.observable(null),
20-
isRequired: captchaData.isRequired,
20+
isRequired: ko.observable(captchaData.isRequired),
2121
isCaseSensitive: captchaData.isCaseSensitive,
2222
imageHeight: captchaData.imageHeight,
2323
refreshUrl: captchaData.refreshUrl,
@@ -41,7 +41,7 @@ define([
4141
* @return {Boolean}
4242
*/
4343
getIsVisible: function () {
44-
return this.visibility;
44+
return this.visibility();
4545
},
4646

4747
/**
@@ -55,14 +55,14 @@ define([
5555
* @return {Boolean}
5656
*/
5757
getIsRequired: function () {
58-
return this.isRequired;
58+
return this.isRequired();
5959
},
6060

6161
/**
6262
* @param {Boolean} flag
6363
*/
6464
setIsRequired: function (flag) {
65-
this.isRequired = flag;
65+
this.isRequired(flag);
6666
},
6767

6868
/**

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/defaultCaptcha.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ define([
8989
return this.currentCaptcha !== null ? this.currentCaptcha.getIsRequired() : false;
9090
},
9191

92+
/**
93+
* @param {Boolean} flag
94+
*/
95+
setIsRequired: function (flag) {
96+
this.currentCaptcha.setIsRequired(flag);
97+
},
98+
9299
/**
93100
* @return {Boolean}
94101
*/

app/code/Magento/Captcha/view/frontend/web/js/view/checkout/loginCaptcha.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,44 @@
44
*/
55

66
define([
7-
'Magento_Captcha/js/view/checkout/defaultCaptcha',
8-
'Magento_Captcha/js/model/captchaList',
9-
'Magento_Customer/js/action/login'
10-
],
11-
function (defaultCaptcha, captchaList, loginAction) {
12-
'use strict';
13-
14-
return defaultCaptcha.extend({
15-
/** @inheritdoc */
16-
initialize: function () {
17-
var self = this,
18-
currentCaptcha;
19-
20-
this._super();
21-
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
22-
23-
if (currentCaptcha != null) {
24-
currentCaptcha.setIsVisible(true);
25-
this.setCurrentCaptcha(currentCaptcha);
26-
27-
loginAction.registerLoginCallback(function (loginData) {
28-
if (loginData['captcha_form_id'] &&
29-
loginData['captcha_form_id'] == self.formId //eslint-disable-line eqeqeq
30-
) {
7+
'underscore',
8+
'Magento_Captcha/js/view/checkout/defaultCaptcha',
9+
'Magento_Captcha/js/model/captchaList',
10+
'Magento_Customer/js/action/login'
11+
],
12+
function (_, defaultCaptcha, captchaList, loginAction) {
13+
'use strict';
14+
15+
return defaultCaptcha.extend({
16+
/** @inheritdoc */
17+
initialize: function () {
18+
var self = this,
19+
currentCaptcha;
20+
21+
this._super();
22+
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
23+
24+
if (currentCaptcha != null) {
25+
currentCaptcha.setIsVisible(true);
26+
this.setCurrentCaptcha(currentCaptcha);
27+
28+
loginAction.registerLoginCallback(function (loginData, response) {
29+
if (!loginData['captcha_form_id'] || loginData['captcha_form_id'] !== self.formId) {
30+
return;
31+
}
32+
33+
if (_.isUndefined(response) || !response.errors) {
34+
return;
35+
}
36+
37+
// check if captcha should be required after login attempt
38+
if (!self.isRequired() && response.captcha && self.isRequired() !== response.captcha) {
39+
self.setIsRequired(response.captcha);
40+
}
41+
3142
self.refresh();
32-
}
33-
});
43+
});
44+
}
3445
}
35-
}
46+
});
3647
});
37-
});

app/code/Magento/Captcha/view/frontend/web/template/checkout/captcha.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
* See COPYING.txt for license details.
55
*/
66
-->
7+
<!-- ko if: (getIsVisible())-->
8+
<input name="captcha_form_id" type="hidden" data-bind="value: formId, attr: {'data-scope': dataScope}" />
9+
<!-- /ko -->
710
<!-- ko if: (isRequired() && getIsVisible())-->
811
<div class="field captcha required" data-bind="blockLoader: getIsLoading()">
912
<label data-bind="attr: {for: 'captcha_' + formId}" class="label"><span data-bind="i18n: 'Please type the letters and numbers below'"></span></label>
1013
<div class="control captcha">
11-
<input name="captcha_string" type="text" class="input-text required-entry" data-bind="value: captchaValue(), attr: {id: 'captcha_' + formId, 'data-scope': dataScope}" autocomplete="off"/>
12-
<input name="captcha_form_id" type="hidden" data-bind="value: formId, attr: {'data-scope': dataScope}" />
14+
<input name="captcha_string" type="text" class="input-text required-entry" data-bind="value: captchaValue(), attr: {'data-scope': dataScope}" autocomplete="off"/>
1315
<div class="nested">
1416
<div class="field captcha no-label">
1517
<div class="control captcha-image">

app/code/Magento/Catalog/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,13 @@
602602
</argument>
603603
</arguments>
604604
</type>
605+
<type name="Magento\Sales\Model\Order\ProductOption">
606+
<arguments>
607+
<argument name="processorPool" xsi:type="array">
608+
<item name="custom_options" xsi:type="object">Magento\Catalog\Model\ProductOptionProcessor</item>
609+
</argument>
610+
</arguments>
611+
</type>
605612
<type name="Magento\Framework\Model\Entity\RepositoryFactory">
606613
<arguments>
607614
<argument name="entities" xsi:type="array">

0 commit comments

Comments
 (0)