Skip to content

Commit aa1b000

Browse files
Merge remote-tracking branch 'origin/2.2-develop' into MAGETWO-91932
2 parents 3861279 + b1e26d5 commit aa1b000

File tree

176 files changed

+3967
-1837
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+3967
-1837
lines changed

app/code/Magento/Analytics/Model/Cryptographer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ private function getInitializationVector()
124124
*/
125125
private function validateCipherMethod($cipherMethod)
126126
{
127-
$methods = openssl_get_cipher_methods();
127+
$methods = array_map(
128+
'strtolower',
129+
openssl_get_cipher_methods()
130+
);
131+
$cipherMethod = strtolower($cipherMethod);
132+
128133
return (false !== array_search($cipherMethod, $methods));
129134
}
130135
}

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,11 @@ public function getSku($product)
310310
$selectionIds = $this->serializer->unserialize($customOption->getValue());
311311
if (!empty($selectionIds)) {
312312
$selections = $this->getSelectionsByIds($selectionIds, $product);
313-
foreach ($selections->getItems() as $selection) {
314-
$skuParts[] = $selection->getSku();
313+
foreach ($selectionIds as $selectionId) {
314+
$entity = $selections->getItemByColumnValue('selection_id', $selectionId);
315+
if (isset($entity) && $entity->getEntityId()) {
316+
$skuParts[] = $entity->getSku();
317+
}
315318
}
316319
}
317320
}

app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ public function testGetSkuWithoutType()
15951595
->disableOriginalConstructor()
15961596
->getMock();
15971597
$selectionItemMock = $this->getMockBuilder(\Magento\Framework\DataObject::class)
1598-
->setMethods(['getSku', '__wakeup'])
1598+
->setMethods(['getSku', 'getEntityId', '__wakeup'])
15991599
->disableOriginalConstructor()
16001600
->getMock();
16011601

@@ -1623,9 +1623,12 @@ public function testGetSkuWithoutType()
16231623
->will($this->returnValue($serializeIds));
16241624
$selectionMock = $this->getSelectionsByIdsMock($selectionIds, $productMock, 5, 6);
16251625
$selectionMock->expects(($this->any()))
1626-
->method('getItems')
1627-
->will($this->returnValue([$selectionItemMock]));
1628-
$selectionItemMock->expects($this->any())
1626+
->method('getItemByColumnValue')
1627+
->will($this->returnValue($selectionItemMock));
1628+
$selectionItemMock->expects($this->at(0))
1629+
->method('getEntityId')
1630+
->will($this->returnValue(1));
1631+
$selectionItemMock->expects($this->once())
16291632
->method('getSku')
16301633
->will($this->returnValue($itemSku));
16311634

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@
140140
</argument>
141141
</arguments>
142142
</type>
143+
<type name="Magento\Sales\Model\Order\ProductOption">
144+
<arguments>
145+
<argument name="processorPool" xsi:type="array">
146+
<item name="bundle" xsi:type="object">Magento\Bundle\Model\ProductOptionProcessor</item>
147+
</argument>
148+
</arguments>
149+
</type>
143150
<type name="Magento\Bundle\Ui\DataProvider\Product\Listing\Collector\BundlePrice">
144151
<arguments>
145152
<argument name="excludeAdjustments" xsi:type="array">

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
namespace Magento\Captcha\Model\Customer\Plugin;
88

99
use Magento\Captcha\Helper\Data as CaptchaHelper;
10-
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\Customer\Controller\Ajax\Login;
11+
use Magento\Framework\Controller\Result\Json;
1112
use Magento\Framework\Controller\Result\JsonFactory;
13+
use Magento\Framework\Session\SessionManagerInterface;
1214

15+
/**
16+
* The plugin for ajax login controller.
17+
*/
1318
class AjaxLogin
1419
{
1520
/**
@@ -61,14 +66,14 @@ public function __construct(
6166
}
6267

6368
/**
64-
* @param \Magento\Customer\Controller\Ajax\Login $subject
69+
* Validates captcha during request execution.
70+
*
71+
* @param Login $subject
6572
* @param \Closure $proceed
6673
* @return $this
67-
* @SuppressWarnings(PHPMD.NPathComplexity)
68-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
6974
*/
7075
public function aroundExecute(
71-
\Magento\Customer\Controller\Ajax\Login $subject,
76+
Login $subject,
7277
\Closure $proceed
7378
) {
7479
$captchaFormIdField = 'captcha_form_id';
@@ -93,26 +98,31 @@ public function aroundExecute(
9398
foreach ($this->formIds as $formId) {
9499
if ($formId === $loginFormId) {
95100
$captchaModel = $this->helper->getCaptcha($formId);
101+
96102
if ($captchaModel->isRequired($username)) {
97-
$captchaModel->logAttempt($username);
98103
if (!$captchaModel->isCorrect($captchaString)) {
99104
$this->sessionManager->setUsername($username);
100-
return $this->returnJsonError(__('Incorrect CAPTCHA'));
105+
$captchaModel->logAttempt($username);
106+
return $this->returnJsonError(__('Incorrect CAPTCHA'), true);
101107
}
102108
}
109+
110+
$captchaModel->logAttempt($username);
103111
}
104112
}
105113
return $proceed();
106114
}
107115

108116
/**
117+
* Gets Json response.
109118
*
110119
* @param \Magento\Framework\Phrase $phrase
111-
* @return \Magento\Framework\Controller\Result\Json
120+
* @param bool $isCaptchaRequired
121+
* @return Json
112122
*/
113-
private function returnJsonError(\Magento\Framework\Phrase $phrase): \Magento\Framework\Controller\Result\Json
123+
private function returnJsonError(\Magento\Framework\Phrase $phrase, bool $isCaptchaRequired = false): Json
114124
{
115125
$resultJson = $this->resultJsonFactory->create();
116-
return $resultJson->setData(['errors' => true, 'message' => $phrase]);
126+
return $resultJson->setData(['errors' => true, 'message' => $phrase, 'captcha' => $isCaptchaRequired]);
117127
}
118128
}

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
@@ -149,7 +149,7 @@ public function testAroundExecuteIncorrectCaptcha()
149149
$this->resultJsonMock
150150
->expects($this->once())
151151
->method('setData')
152-
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA')])
152+
->with(['errors' => true, 'message' => __('Incorrect CAPTCHA'), 'captcha' => true])
153153
->will($this->returnSelf());
154154

155155
$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-
});

0 commit comments

Comments
 (0)