Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 7c013a1

Browse files
authored
Merge pull request #3 from magento/2.2-develop
2.2 develop-update branch
2 parents 301d73d + 06aca23 commit 7c013a1

File tree

110 files changed

+1949
-683
lines changed

Some content is hidden

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

110 files changed

+1949
-683
lines changed

app/code/Magento/Backup/Controller/Adminhtml/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class Index extends \Magento\Backend\App\Action
1919
*
2020
* @see _isAllowed()
2121
*/
22-
const ADMIN_RESOURCE = 'Magento_Backend::backup';
22+
const ADMIN_RESOURCE = 'Magento_Backup::backup';
2323

2424
/**
2525
* Core registry

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

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/Helper/Data.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011
use Magento\Customer\Model\Session as CustomerSession;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -269,7 +270,8 @@ public function setStoreId($store)
269270

270271
/**
271272
* Return current category path or get it from current category
272-
* and creating array of categories|product paths for breadcrumbs
273+
*
274+
* Creating array of categories|product paths for breadcrumbs
273275
*
274276
* @return array
275277
*/
@@ -378,6 +380,7 @@ public function getLastViewedUrl()
378380

379381
/**
380382
* Split SKU of an item by dashes and spaces
383+
*
381384
* Words will not be broken, unless this length is greater than $length
382385
*
383386
* @param string $sku
@@ -406,14 +409,15 @@ public function getAttributeHiddenFields()
406409
/**
407410
* Retrieve Catalog Price Scope
408411
*
409-
* @return int
412+
* @return int|null
410413
*/
411414
public function getPriceScope()
412415
{
413-
return $this->scopeConfig->getValue(
416+
$priceScope = $this->scopeConfig->getValue(
414417
self::XML_PATH_PRICE_SCOPE,
415-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
418+
ScopeInterface::SCOPE_STORE
416419
);
420+
return isset($priceScope) ? (int)$priceScope : null;
417421
}
418422

419423
/**
@@ -449,7 +453,7 @@ public function isUrlDirectivesParsingAllowed()
449453
{
450454
return $this->scopeConfig->isSetFlag(
451455
self::CONFIG_PARSE_URL_DIRECTIVES,
452-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
456+
ScopeInterface::SCOPE_STORE,
453457
$this->_storeId
454458
);
455459
}
@@ -466,19 +470,22 @@ public function getPageTemplateProcessor()
466470

467471
/**
468472
* Whether to display items count for each filter option
473+
*
469474
* @param int $storeId Store view ID
470475
* @return bool
471476
*/
472477
public function shouldDisplayProductCountOnLayer($storeId = null)
473478
{
474479
return $this->scopeConfig->isSetFlag(
475480
self::XML_PATH_DISPLAY_PRODUCT_COUNT,
476-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
481+
ScopeInterface::SCOPE_STORE,
477482
$storeId
478483
);
479484
}
480485

481486
/**
487+
* Convert tax address array to address data object with country id and postcode
488+
*
482489
* @param array $taxAddress
483490
* @return \Magento\Customer\Api\Data\AddressInterface|null
484491
*/

app/code/Magento/Catalog/Model/Design.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Model;
77

8+
use \Magento\Framework\TranslateInterface;
9+
810
/**
911
* Catalog Custom Category design Model
1012
*
@@ -31,6 +33,11 @@ class Design extends \Magento\Framework\Model\AbstractModel
3133
*/
3234
protected $_localeDate;
3335

36+
/**
37+
* @var TranslateInterface
38+
*/
39+
private $translator;
40+
3441
/**
3542
* @param \Magento\Framework\Model\Context $context
3643
* @param \Magento\Framework\Registry $registry
@@ -47,10 +54,13 @@ public function __construct(
4754
\Magento\Framework\View\DesignInterface $design,
4855
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
4956
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
50-
array $data = []
57+
array $data = [],
58+
TranslateInterface $translator = null
5159
) {
5260
$this->_localeDate = $localeDate;
5361
$this->_design = $design;
62+
$this->translator = $translator ?:
63+
\Magento\Framework\App\ObjectManager::getInstance()->get(TranslateInterface::class);
5464
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
5565
}
5666

@@ -63,6 +73,7 @@ public function __construct(
6373
public function applyCustomDesign($design)
6474
{
6575
$this->_design->setDesignTheme($design);
76+
$this->translator->loadData(null, true);
6677
return $this;
6778
}
6879

0 commit comments

Comments
 (0)