Skip to content

Commit a6c4c89

Browse files
author
Sergii Kovalenko
committed
Merge branch 'develop' into MAGETWO-53349
2 parents 9453346 + 7bbb2bf commit a6c4c89

File tree

50 files changed

+787
-127
lines changed

Some content is hidden

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

50 files changed

+787
-127
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ define(
2626
},
2727
initialize: function() {
2828
this._super();
29-
captchaConfig = window[this.configSource]['captcha'];
3029

31-
if (captchaConfig) {
30+
if (window[this.configSource] && window[this.configSource]['captcha']) {
31+
captchaConfig = window[this.configSource]['captcha'];
3232
$.each(captchaConfig, function(formId, captchaData) {
3333
captchaData.formId = formId;
3434
captchaList.add(Captcha(captchaData));

app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AttributeMerger
4545
'alphanumeric' => 'validate-alphanum',
4646
'url' => 'validate-url',
4747
'email' => 'email2',
48+
'length' => 'validate-length',
4849
];
4950

5051
/**

app/code/Magento/Customer/Helper/Address.php

+6-13
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ class Address extends \Magento\Framework\App\Helper\AbstractHelper
7171
/** @var \Magento\Store\Model\StoreManagerInterface */
7272
protected $_storeManager;
7373

74-
/** @var CustomerMetadataInterface */
74+
/**
75+
* @var CustomerMetadataInterface
76+
*
77+
* @deprecated
78+
*/
7579
protected $_customerMetadataService;
7680

7781
/** @var AddressMetadataInterface */
@@ -243,19 +247,8 @@ public function getAttributeValidationClass($attributeCode)
243247
$attribute = isset($this->_attributes[$attributeCode])
244248
? $this->_attributes[$attributeCode]
245249
: $this->_addressMetadataService->getAttributeMetadata($attributeCode);
246-
$class = $attribute ? $attribute->getFrontendClass() : '';
247-
if (in_array($attributeCode, ['firstname', 'middlename', 'lastname', 'prefix', 'suffix', 'taxvat'])) {
248-
if ($class && !$attribute->isVisible()) {
249-
// address attribute is not visible thus its validation rules are not applied
250-
$class = '';
251-
}
252250

253-
/** @var $customerAttribute AttributeMetadataInterface */
254-
$customerAttribute = $this->_customerMetadataService->getAttributeMetadata($attributeCode);
255-
$class .= $customerAttribute &&
256-
$customerAttribute->isVisible() ? $customerAttribute->getFrontendClass() : '';
257-
$class = implode(' ', array_unique(array_filter(explode(' ', $class))));
258-
}
251+
$class = $attribute ? $attribute->getFrontendClass() : '';
259252
} catch (NoSuchEntityException $e) {
260253
// the attribute does not exist so just return an empty string
261254
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -717,16 +717,17 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
717717
}
718718
try {
719719
foreach ($customerAddresses as $address) {
720-
if ($address->getId()) {
720+
if ($address->getId()) {
721721
$newAddress = clone $address;
722722
$newAddress->setId(null);
723723
$newAddress->setCustomerId($customer->getId());
724724
$this->addressRepository->save($newAddress);
725-
} else {
725+
} else {
726726
$address->setCustomerId($customer->getId());
727727
$this->addressRepository->save($address);
728728
}
729729
}
730+
$this->customerRegistry->remove($customer->getId());
730731
} catch (InputException $e) {
731732
$this->customerRepository->delete($customer);
732733
throw $e;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public function updateData($customer)
321321
{
322322
$customerDataAttributes = $this->dataObjectProcessor->buildOutputDataArray(
323323
$customer,
324-
'\Magento\Customer\Api\Data\CustomerInterface'
324+
\Magento\Customer\Api\Data\CustomerInterface::class
325325
);
326326

327327
foreach ($customerDataAttributes as $attributeCode => $attributeData) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Form extends \Magento\Eav\Model\Form
1616
/**
1717
* XML configuration paths for "Disable autocomplete on storefront" property
1818
*/
19-
const XML_PATH_ENABLE_AUTOCOMPLETE = 'general/restriction/autocomplete_on_storefront';
19+
const XML_PATH_ENABLE_AUTOCOMPLETE = 'customer/password/autocomplete_on_storefront';
2020

2121
/**
2222
* Current module pathname

app/code/Magento/Customer/Model/ResourceModel/Address.php

+33-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
*/
88
namespace Magento\Customer\Model\ResourceModel;
99

10+
use Magento\Customer\Controller\Adminhtml\Group\Delete;
11+
use Magento\Customer\Model\CustomerRegistry;
12+
use Magento\Customer\Model\ResourceModel\Address\DeleteRelation;
13+
use Magento\Framework\App\ObjectManager;
14+
15+
/**
16+
* Class Address
17+
* @package Magento\Customer\Model\ResourceModel
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
1020
class Address extends \Magento\Eav\Model\Entity\VersionControl\AbstractEntity
1121
{
1222
/**
@@ -110,20 +120,32 @@ public function delete($object)
110120
}
111121

112122
/**
113-
* {@inheritdoc}
123+
* @deprecated
124+
* @return DeleteRelation
125+
*/
126+
private function getDeleteRelation()
127+
{
128+
return ObjectManager::getInstance()->get(DeleteRelation::class);
129+
}
130+
131+
/**
132+
* @deprecated
133+
* @return CustomerRegistry
134+
*/
135+
private function getCustomerRegistry()
136+
{
137+
return ObjectManager::getInstance()->get(CustomerRegistry::class);
138+
}
139+
140+
/**
141+
* @param \Magento\Customer\Model\Address $address
142+
* @return $this
114143
*/
115144
protected function _afterDelete(\Magento\Framework\DataObject $address)
116145
{
117-
if ($address->getId()) {
118-
$customer = $this->customerRepository->getById($address->getCustomerId());
119-
if ($customer->getDefaultBilling() == $address->getId()) {
120-
$customer->setDefaultBilling(null);
121-
}
122-
if ($customer->getDefaultShipping() == $address->getId()) {
123-
$customer->setDefaultShipping(null);
124-
}
125-
$this->customerRepository->save($customer);
126-
}
146+
$customer = $this->getCustomerRegistry()->retrieve($address->getCustomerId());
147+
148+
$this->getDeleteRelation()->deleteRelation($address, $customer);
127149
return parent::_afterDelete($address);
128150
}
129151
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\ResourceModel\Address;
7+
8+
use Magento\Customer\Api\Data\CustomerInterface;
9+
10+
/**
11+
* Class DeleteRelation
12+
* @package Magento\Customer\Model\ResourceModel\Address
13+
*/
14+
class DeleteRelation
15+
{
16+
/**
17+
* Delete relation (billing and shipping) between customer and address
18+
*
19+
* @param \Magento\Framework\Model\AbstractModel $address
20+
* @param \Magento\Customer\Model\Customer $customer
21+
* @return void
22+
*/
23+
public function deleteRelation(
24+
\Magento\Framework\Model\AbstractModel $address,
25+
\Magento\Customer\Model\Customer $customer
26+
) {
27+
$toUpdate = $this->getDataToUpdate($address, $customer);
28+
29+
if (!$address->getIsCustomerSaveTransaction() && !empty($toUpdate)) {
30+
$address->getResource()->getConnection()->update(
31+
$address->getResource()->getTable('customer_entity'),
32+
$toUpdate,
33+
$address->getResource()->getConnection()->quoteInto('entity_id = ?', $customer->getId())
34+
);
35+
}
36+
}
37+
38+
/**
39+
* Return address type (billing or shipping), or null if address is not default
40+
*
41+
* @param \Magento\Customer\Api\Data\AddressInterface $address
42+
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
43+
* @return array
44+
*/
45+
private function getDataToUpdate(
46+
\Magento\Framework\Model\AbstractModel $address,
47+
\Magento\Customer\Model\Customer $customer
48+
) {
49+
$toUpdate = [];
50+
if ($address->getId()) {
51+
if ($customer->getDefaultBilling() == $address->getId()) {
52+
$toUpdate[CustomerInterface::DEFAULT_BILLING] = null;
53+
}
54+
55+
if ($customer->getDefaultShipping() == $address->getId()) {
56+
$toUpdate[CustomerInterface::DEFAULT_SHIPPING] = null;
57+
}
58+
}
59+
60+
return $toUpdate;
61+
}
62+
}

app/code/Magento/Customer/Model/ResourceModel/AddressRepository.php

+15-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Customer\Model\ResourceModel;
99

1010
use Magento\Customer\Model\Address as CustomerAddressModel;
11+
use Magento\Customer\Model\Customer as CustomerModel;
1112
use Magento\Customer\Model\ResourceModel\Address\Collection;
1213
use Magento\Framework\Api\Search\FilterGroup;
1314
use Magento\Framework\Api\SearchCriteriaInterface;
@@ -123,13 +124,24 @@ public function save(\Magento\Customer\Api\Data\AddressInterface $address)
123124
$address->setId($addressModel->getId());
124125
// Clean up the customer registry since the Address save has a
125126
// side effect on customer : \Magento\Customer\Model\ResourceModel\Address::_afterSave
126-
$this->customerRegistry->remove($address->getCustomerId());
127127
$this->addressRegistry->push($addressModel);
128-
$customerModel->getAddressesCollection()->clear();
128+
$this->updateAddressCollection($customerModel, $addressModel);
129129

130130
return $addressModel->getDataModel();
131131
}
132132

133+
/**
134+
* @param Customer $customer
135+
* @param Address $address
136+
* @throws \Magento\Framework\Exception\LocalizedException
137+
* @return void
138+
*/
139+
private function updateAddressCollection(CustomerModel $customer, CustomerAddressModel $address)
140+
{
141+
$customer->getAddressesCollection()->removeItemByKey($address->getId());
142+
$customer->getAddressesCollection()->addItem($address);
143+
}
144+
133145
/**
134146
* Retrieve customer address.
135147
*
@@ -236,7 +248,7 @@ public function deleteById($addressId)
236248
{
237249
$address = $this->addressRegistry->retrieve($addressId);
238250
$customerModel = $this->customerRegistry->retrieve($address->getCustomerId());
239-
$customerModel->getAddressesCollection()->clear();
251+
$customerModel->getAddressesCollection()->removeItemByKey($addressId);
240252
$this->addressResource->delete($address);
241253
$this->addressRegistry->remove($addressId);
242254
return true;

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
207207
$this->addressRepository->deleteById($addressId);
208208
}
209209
}
210-
210+
$this->customerRegistry->remove($customerId);
211211
$savedCustomer = $this->get($customer->getEmail(), $customer->getWebsiteId());
212212
$this->eventManager->dispatch(
213213
'customer_save_after_data_object',
@@ -221,6 +221,7 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
221221
*
222222
* @param \Magento\Customer\Model\Customer $customerModel
223223
* @param string|null $passwordHash
224+
* @SuppressWarnings(PHPMD.NPathComplexity)
224225
* @return void
225226
*/
226227
private function populateCustomerWithSecureData($customerModel, $passwordHash = null)

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

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct(
5353
/**
5454
* {@inheritdoc}
5555
* @SuppressWarnings(PHPMD.NPathComplexity)
56+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5657
*/
5758
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
5859
{
@@ -91,6 +92,14 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
9192
);
9293
}
9394

95+
if (version_compare($context->getVersion(), '2.0.8', '<')) {
96+
$setup->getConnection()->update(
97+
$setup->getTable('core_config_data'),
98+
['path' => \Magento\Customer\Model\Form::XML_PATH_ENABLE_AUTOCOMPLETE],
99+
['path = ?' => 'general/restriction/autocomplete_on_storefront']
100+
);
101+
}
102+
94103
if (version_compare($context->getVersion(), '2.0.7', '<')) {
95104
$this->upgradeVersionTwoZeroSeven($customerSetup);
96105
$this->upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup);

app/code/Magento/Customer/Test/Unit/Controller/Address/FormPostTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Customer\Api\Data\RegionInterface;
1212
use Magento\Customer\Api\Data\RegionInterfaceFactory;
1313
use Magento\Customer\Controller\Address\FormPost;
14+
use Magento\Customer\Model\CustomerRegistry;
1415
use Magento\Customer\Model\Metadata\Form;
1516
use Magento\Customer\Model\Metadata\FormFactory;
1617
use Magento\Customer\Model\Session;
@@ -19,6 +20,7 @@
1920
use Magento\Directory\Model\RegionFactory;
2021
use Magento\Framework\Api\DataObjectHelper;
2122
use Magento\Framework\App\Action\Context;
23+
use Magento\Framework\App\ObjectManager;
2224
use Magento\Framework\App\RequestInterface;
2325
use Magento\Framework\App\Response\RedirectInterface;
2426
use Magento\Framework\Controller\Result\ForwardFactory;
@@ -439,12 +441,14 @@ public function testExecute(
439441
'region_id' => $regionId,
440442
'region' => $region,
441443
'region_code' => $regionCode,
444+
'customer_id' => $customerId
442445
];
443446
$newAddressData = [
444447
'country_id' => $countryId,
445448
'region_id' => $newRegionId,
446449
'region' => $newRegion,
447450
'region_code' => $newRegionCode,
451+
'customer_id' => $customerId
448452
];
449453

450454
$url = 'success_url';
@@ -530,7 +534,7 @@ public function testExecute(
530534
$this->session->expects($this->atLeastOnce())
531535
->method('getCustomerId')
532536
->willReturn($customerId);
533-
$this->addressData->expects($this->once())
537+
$this->addressData->expects($this->any())
534538
->method('getCustomerId')
535539
->willReturn($customerId);
536540

app/code/Magento/Customer/Test/Unit/Helper/AddressTest.php

+18-24
Original file line numberDiff line numberDiff line change
@@ -147,39 +147,33 @@ public function testGetConfigCanShowConfig()
147147
$this->assertTrue($this->helper->canShowConfig('key2'));
148148
}
149149

150-
/**
151-
* @param $attrCode
152-
* @param $attrClass
153-
* @param $customAttrClass
154-
* @param $result
155-
* @dataProvider getAttributeValidationClassDataProvider
156-
*/
157-
public function testGetAttributeValidationClass($attrCode, $attrClass, $customAttrClass, $result)
150+
public function testGetAttributeValidationClass()
158151
{
159-
$attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface')->getMock();
160-
$attributeMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($attrClass));
152+
$attributeCode = 'attr_code';
153+
$attributeClass = 'Attribute_Class';
161154

162-
$customAttrMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface')->getMock();
163-
$customAttrMock->expects($this->any())->method('isVisible')->will($this->returnValue(true));
164-
$customAttrMock->expects($this->any())->method('getFrontendClass')->will($this->returnValue($customAttrClass));
165-
166-
$this->customerMetadataService->expects($this->any())
167-
->method('getAttributeMetadata')
168-
->will($this->returnValue($customAttrMock));
155+
$attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface')
156+
->getMockForAbstractClass();
157+
$attributeMock->expects($this->once())
158+
->method('getFrontendClass')
159+
->willReturn($attributeClass);
169160

170161
$this->addressMetadataService->expects($this->any())
171162
->method('getAttributeMetadata')
172-
->will($this->returnValue($attributeMock));
163+
->willReturn($attributeMock);
173164

174-
$this->assertEquals($result, $this->helper->getAttributeValidationClass($attrCode));
165+
$this->assertEquals($attributeClass, $this->helper->getAttributeValidationClass($attributeCode));
175166
}
176167

177-
public function getAttributeValidationClassDataProvider()
168+
public function testGetAttributeValidationClassWithNoAttribute()
178169
{
179-
return [
180-
['attr_code', 'Attribute_Class', '', 'Attribute_Class'],
181-
['firstname', 'Attribute_Class', 'Attribute2_Class', 'Attribute2_Class'],
182-
];
170+
$attrCode = 'attr_code';
171+
172+
$this->addressMetadataService->expects($this->any())
173+
->method('getAttributeMetadata')
174+
->willReturn(null);
175+
176+
$this->assertEquals('', $this->helper->getAttributeValidationClass($attrCode));
183177
}
184178

185179
/**

0 commit comments

Comments
 (0)