Skip to content

Commit 071ec6b

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-54819
2 parents 28f5787 + 2a70b82 commit 071ec6b

File tree

17 files changed

+456
-61
lines changed

17 files changed

+456
-61
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/view/addtocart.phtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
</div>
4141
</div>
4242
<?php endif; ?>
43+
<?php if ($block->isRedirectToCartEnabled()) : ?>
4344
<script type="text/x-magento-init">
4445
{
4546
"#product_addtocart_form": {
@@ -49,11 +50,11 @@
4950
}
5051
}
5152
</script>
52-
<?php if (!$block->isRedirectToCartEnabled()) : ?>
53+
<?php else : ?>
5354
<script type="text/x-magento-init">
5455
{
5556
"#product_addtocart_form": {
56-
"catalogAddToCart": {}
57+
"Magento_Catalog/js/validate-product": {}
5758
}
5859
}
5960
</script>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'mage/mage',
8+
'Magento_Catalog/product/view/validation',
9+
'catalogAddToCart'
10+
], function ($) {
11+
'use strict';
12+
13+
$.widget('mage.productValidate', {
14+
options: {
15+
bindSubmit: false,
16+
radioCheckboxClosest: '.nested'
17+
},
18+
19+
/**
20+
* Uses Magento's validation widget for the form object.
21+
* @private
22+
*/
23+
_create: function () {
24+
var bindSubmit = this.options.bindSubmit;
25+
26+
this.element.validation({
27+
radioCheckboxClosest: this.options.radioCheckboxClosest,
28+
29+
/**
30+
* Uses catalogAddToCart widget as submit handler.
31+
* @param {Object} form
32+
* @returns {Boolean}
33+
*/
34+
submitHandler: function (form) {
35+
var jqForm = $(form).catalogAddToCart({
36+
bindSubmit: bindSubmit
37+
});
38+
39+
jqForm.catalogAddToCart('submitForm', jqForm);
40+
41+
return false;
42+
}
43+
});
44+
}
45+
});
46+
47+
return $.mage.productValidate;
48+
});

app/code/Magento/Customer/Model/Authentication.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
namespace Magento\Customer\Model;
77

88
use Magento\Customer\Api\CustomerRepositoryInterface;
9+
use Magento\Customer\Model\ResourceModel\CustomerRepository;
10+
use Magento\Customer\Model\CustomerAuthUpdate;
911
use Magento\Backend\App\ConfigInterface;
1012
use Magento\Framework\Encryption\EncryptorInterface as Encryptor;
1113
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
1214
use Magento\Framework\Exception\State\UserLockedException;
1315

16+
/**
17+
* Class Authentication
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
1420
class Authentication implements AuthenticationInterface
1521
{
1622
/**
@@ -50,6 +56,11 @@ class Authentication implements AuthenticationInterface
5056
*/
5157
protected $customerRepository;
5258

59+
/**
60+
* @var CustomerAuthUpdate
61+
*/
62+
private $customerAuthUpdate;
63+
5364
/**
5465
* @param CustomerRepositoryInterface $customerRepository
5566
* @param CustomerRegistry $customerRegistry
@@ -105,7 +116,7 @@ public function processAuthenticationFailure($customerId)
105116
}
106117

107118
$customerSecure->setFailuresNum($failuresNum);
108-
$this->customerRepository->save($this->customerRepository->getById($customerId));
119+
$this->getCustomerAuthUpdate()->saveAuth($customerId);
109120
}
110121

111122
/**
@@ -117,7 +128,7 @@ public function unlock($customerId)
117128
$customerSecure->setFailuresNum(0);
118129
$customerSecure->setFirstFailure(null);
119130
$customerSecure->setLockExpires(null);
120-
$this->customerRepository->save($this->customerRepository->getById($customerId));
131+
$this->getCustomerAuthUpdate()->saveAuth($customerId);
121132
}
122133

123134
/**
@@ -165,4 +176,19 @@ public function authenticate($customerId, $password)
165176
}
166177
return true;
167178
}
179+
180+
/**
181+
* Get customer authentication update model
182+
*
183+
* @return \Magento\Customer\Model\CustomerAuthUpdate
184+
* @deprecated
185+
*/
186+
private function getCustomerAuthUpdate()
187+
{
188+
if ($this->customerAuthUpdate === null) {
189+
$this->customerAuthUpdate =
190+
\Magento\Framework\App\ObjectManager::getInstance()->get(CustomerAuthUpdate::class);
191+
}
192+
return $this->customerAuthUpdate;
193+
}
168194
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model;
8+
9+
/**
10+
* Customer Authentication update model.
11+
*/
12+
class CustomerAuthUpdate
13+
{
14+
/**
15+
* @var \Magento\Customer\Model\CustomerRegistry
16+
*/
17+
protected $customerRegistry;
18+
19+
/**
20+
* @var \Magento\Customer\Model\ResourceModel\Customer
21+
*/
22+
protected $customerResourceModel;
23+
24+
/**
25+
* @param \Magento\Customer\Model\CustomerRegistry $customerRegistry
26+
* @param \Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
27+
*/
28+
public function __construct(
29+
\Magento\Customer\Model\CustomerRegistry $customerRegistry,
30+
\Magento\Customer\Model\ResourceModel\Customer $customerResourceModel
31+
) {
32+
$this->customerRegistry = $customerRegistry;
33+
$this->customerResourceModel = $customerResourceModel;
34+
}
35+
36+
/**
37+
* Reset Authentication data for customer.
38+
*
39+
* @param int $customerId
40+
* @return $this
41+
*/
42+
public function saveAuth($customerId)
43+
{
44+
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
45+
46+
$this->customerResourceModel->getConnection()->update(
47+
$this->customerResourceModel->getTable('customer_entity'),
48+
[
49+
'failures_num' => $customerSecure->getData('failures_num'),
50+
'first_failure' => $customerSecure->getData('first_failure'),
51+
'lock_expires' => $customerSecure->getData('lock_expires'),
52+
],
53+
$this->customerResourceModel->getConnection()->quoteInto('entity_id = ?', $customerId)
54+
);
55+
56+
return $this;
57+
}
58+
}

app/code/Magento/Customer/Setup/CustomerSetup.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function getDefaultEntities()
166166
],
167167
'prefix' => [
168168
'type' => 'static',
169-
'label' => 'Prefix',
169+
'label' => 'Name Prefix',
170170
'input' => 'text',
171171
'required' => false,
172172
'sort_order' => 30,
@@ -202,7 +202,7 @@ public function getDefaultEntities()
202202
],
203203
'suffix' => [
204204
'type' => 'static',
205-
'label' => 'Suffix',
205+
'label' => 'Name Suffix',
206206
'input' => 'text',
207207
'required' => false,
208208
'sort_order' => 70,
@@ -350,7 +350,7 @@ public function getDefaultEntities()
350350
'attributes' => [
351351
'prefix' => [
352352
'type' => 'static',
353-
'label' => 'Prefix',
353+
'label' => 'Name Prefix',
354354
'input' => 'text',
355355
'required' => false,
356356
'sort_order' => 10,
@@ -386,7 +386,7 @@ public function getDefaultEntities()
386386
],
387387
'suffix' => [
388388
'type' => 'static',
389-
'label' => 'Suffix',
389+
'label' => 'Name Suffix',
390390
'input' => 'text',
391391
'required' => false,
392392
'sort_order' => 50,

app/code/Magento/Customer/Setup/InstallSchema.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
100100
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
101101
40,
102102
['nullable' => true, 'default' => null],
103-
'Prefix'
103+
'Name Prefix'
104104
)->addColumn(
105105
'firstname',
106106
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
@@ -124,7 +124,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
124124
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
125125
40,
126126
['nullable' => true, 'default' => null],
127-
'Suffix'
127+
'Name Suffix'
128128
)->addColumn(
129129
'dob',
130130
\Magento\Framework\DB\Ddl\Table::TYPE_DATE,
@@ -308,7 +308,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
308308
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
309309
40,
310310
['nullable' => true, 'default' => null],
311-
'Prefix'
311+
'Name Prefix'
312312
)->addColumn(
313313
'region',
314314
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
@@ -332,7 +332,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
332332
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
333333
40,
334334
['nullable' => true, 'default' => null],
335-
'Suffix'
335+
'Name Suffix'
336336
)->addColumn(
337337
'telephone',
338338
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,

app/code/Magento/Customer/Test/Unit/Block/Widget/NameTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class NameTest extends \PHPUnit_Framework_TestCase
4444

4545
const INVALID_ATTRIBUTE_CODE = 'invalid attribute code';
4646

47-
const PREFIX_STORE_LABEL = 'Prefix';
47+
const PREFIX_STORE_LABEL = 'Name Prefix';
4848

4949
/**#@-*/
5050

app/code/Magento/Customer/Test/Unit/Model/AuthenticationTest.php

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,20 @@ class AuthenticationTest extends \PHPUnit_Framework_TestCase
5555
*/
5656
private $dateTimeMock;
5757

58+
/**
59+
* @var \Magento\Customer\Model\CustomerAuthUpdate | \PHPUnit_Framework_MockObject_MockObject
60+
*/
61+
protected $customerAuthUpdate;
62+
63+
/**
64+
* @var ObjectManagerHelper
65+
*/
66+
protected $objectManager;
67+
5868
protected function setUp()
5969
{
70+
$this->objectManager = new ObjectManagerHelper($this);
71+
6072
$this->backendConfigMock = $this->getMockBuilder(ConfigInterface::class)
6173
->disableOriginalConstructor()
6274
->setMethods(['getValue'])
@@ -98,9 +110,11 @@ protected function setUp()
98110
false
99111
);
100112

101-
$objectManagerHelper = new ObjectManagerHelper($this);
113+
$this->customerAuthUpdate = $this->getMockBuilder(\Magento\Customer\Model\CustomerAuthUpdate::class)
114+
->disableOriginalConstructor()
115+
->getMock();
102116

103-
$this->authentication = $objectManagerHelper->getObject(
117+
$this->authentication = $this->objectManager->getObject(
104118
Authentication::class,
105119
[
106120
'customerRegistry' => $this->customerRegistryMock,
@@ -110,6 +124,12 @@ protected function setUp()
110124
'dateTime' => $this->dateTimeMock,
111125
]
112126
);
127+
128+
$this->objectManager->setBackwardCompatibleProperty(
129+
$this->authentication,
130+
'customerAuthUpdate',
131+
$this->customerAuthUpdate
132+
);
113133
}
114134

115135
public function testProcessAuthenticationFailureLockingIsDisabled()
@@ -164,16 +184,10 @@ public function testProcessAuthenticationFailureFirstAttempt(
164184
->method('retrieveSecureData')
165185
->with($customerId)
166186
->willReturn($this->customerSecureMock);
167-
$customerMock = $this->getMockBuilder(CustomerInterface::class)
168-
->disableOriginalConstructor()
169-
->getMock();
170-
$this->customerRepositoryMock->expects($this->once())
171-
->method('getById')
187+
$this->customerAuthUpdate->expects($this->once())
188+
->method('saveAuth')
172189
->with($customerId)
173-
->willReturn($customerMock);
174-
$this->customerRepositoryMock->expects($this->once())
175-
->method('save')
176-
->with($customerMock);
190+
->willReturnSelf();
177191

178192
$this->customerSecureMock->expects($this->once())->method('getFailuresNum')->willReturn($failureNum);
179193
$this->customerSecureMock->expects($this->once())
@@ -210,16 +224,10 @@ public function testUnlock()
210224
->method('retrieveSecureData')
211225
->with($customerId)
212226
->willReturn($this->customerSecureMock);
213-
$customerMock = $this->getMockBuilder(CustomerInterface::class)
214-
->disableOriginalConstructor()
215-
->getMock();
216-
$this->customerRepositoryMock->expects($this->once())
217-
->method('getById')
227+
$this->customerAuthUpdate->expects($this->once())
228+
->method('saveAuth')
218229
->with($customerId)
219-
->willReturn($customerMock);
220-
$this->customerRepositoryMock->expects($this->once())
221-
->method('save')
222-
->with($customerMock);
230+
->willReturnSelf();
223231
$this->customerSecureMock->expects($this->once())->method('setFailuresNum')->with(0);
224232
$this->customerSecureMock->expects($this->once())->method('setFirstFailure')->with(null);
225233
$this->customerSecureMock->expects($this->once())->method('setLockExpires')->with(null);
@@ -312,9 +320,10 @@ public function testAuthenticate($result)
312320
->with($customerId)
313321
->willReturn($this->customerSecureMock);
314322

315-
$this->customerRepositoryMock->expects($this->once())
316-
->method('save')
317-
->willReturn($customerMock);
323+
$this->customerAuthUpdate->expects($this->once())
324+
->method('saveAuth')
325+
->with($customerId)
326+
->willReturnSelf();
318327

319328
$this->setExpectedException(\Magento\Framework\Exception\InvalidEmailOrPasswordException::class);
320329
$this->authentication->authenticate($customerId, $password);

0 commit comments

Comments
 (0)