Skip to content

Commit 68e8c1a

Browse files
author
Yu Tang
committed
Merge branch 'FearlesKiwis-MAGETWO-32892-Customer-Immutability' into FearlessKiwis-MAGETWO-32893-Tax-Immutability
2 parents 82063f3 + 0a19b9d commit 68e8c1a

File tree

5 files changed

+37
-49
lines changed

5 files changed

+37
-49
lines changed

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Addresses.php

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

88
use Magento\Customer\Controller\RegistryConstants;
99
use Magento\Customer\Api\AddressMetadataInterface;
10-
use Magento\Customer\Model\AttributeMetadataDataBuilder;
1110
use Magento\Customer\Api\Data\AddressInterface;
1211
use Magento\Customer\Api\AccountManagementInterface;
1312
use Magento\Customer\Api\Data\AddressInterfaceFactory;
@@ -67,9 +66,6 @@ class Addresses extends GenericMetadata
6766
/** @var CustomerInterfaceFactory */
6867
protected $customerDataFactory;
6968

70-
/** @var AttributeMetadataDataBuilder */
71-
protected $_attributeMetadataBuilder;
72-
7369
/**
7470
* @var AddressMapper
7571
*/
@@ -96,7 +92,6 @@ class Addresses extends GenericMetadata
9692
* @param AddressMetadataInterface $addressMetadataService
9793
* @param AddressInterfaceFactory $addressDataFactory
9894
* @param CustomerInterfaceFactory $customerInterfaceFactory
99-
* @param AttributeMetadataDataBuilder $attributeMetadataBuilder
10095
* @param \Magento\Directory\Helper\Data $directoryHelper
10196
* @param AddressMapper $addressMapper
10297
* @param CustomerMapper $customerMapper
@@ -121,7 +116,6 @@ public function __construct(
121116
AddressMetadataInterface $addressMetadataService,
122117
AddressInterfaceFactory $addressDataFactory,
123118
CustomerInterfaceFactory $customerInterfaceFactory,
124-
AttributeMetadataDataBuilder $attributeMetadataBuilder,
125119
\Magento\Directory\Helper\Data $directoryHelper,
126120
AddressMapper $addressMapper,
127121
DataObjectHelper $dataObjectHelper,
@@ -138,7 +132,6 @@ public function __construct(
138132
$this->_addressMetadataService = $addressMetadataService;
139133
$this->addressDataFactory = $addressDataFactory;
140134
$this->customerDataFactory = $customerInterfaceFactory;
141-
$this->_attributeMetadataBuilder = $attributeMetadataBuilder;
142135
$this->_directoryHelper = $directoryHelper;
143136
$this->addressMapper = $addressMapper;
144137
$this->dataObjectHelper = $dataObjectHelper;
@@ -261,21 +254,12 @@ public function initForm()
261254
$attributes = $addressForm->getAttributes();
262255
if (isset($attributes['street'])) {
263256
if ($attributes['street']->getMultilineCount() <= 0) {
264-
$attributes['street'] = $this->_attributeMetadataBuilder->populate(
265-
$attributes['street']
266-
)->setMultilineCount(
267-
self::DEFAULT_STREET_LINES_COUNT
268-
)->create();
257+
$attributes['street']->setMultilineCount(self::DEFAULT_STREET_LINES_COUNT);
269258
}
270259
}
271260
foreach ($attributes as $key => $attribute) {
272-
$attributes[$key] = $this->_attributeMetadataBuilder->populate(
273-
$attribute
274-
)->setFrontendLabel(
275-
__($attribute->getFrontendLabel())
276-
)->setVisible(
277-
false
278-
)->create();
261+
$attributes[$key]->setFrontendLabel(__($attribute->getFrontendLabel()))
262+
->setIsVisible(false);
279263
}
280264
$this->_setFieldset($attributes, $fieldset);
281265

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

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

88
use Magento\Customer\Api\Data\OptionInterfaceFactory;
99
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
10+
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
1011

1112
/**
1213
* Converter for AttributeMetadata
@@ -24,9 +25,9 @@ class AttributeMetadataConverter
2425
private $validationRuleFactory;
2526

2627
/**
27-
* @var AttributeMetadataDataBuilder
28+
* @var AttributeMetadataInterfaceFactory
2829
*/
29-
private $_attributeMetadataBuilder;
30+
private $attributeMetadataFactory;
3031

3132
/**
3233
* @var \Magento\Framework\Api\DataObjectHelper
@@ -37,18 +38,18 @@ class AttributeMetadataConverter
3738
*
3839
* @param OptionInterfaceFactory $optionFactory
3940
* @param ValidationRuleInterfaceFactory $validationRuleFactory
40-
* @param AttributeMetadataDataBuilder $attributeMetadataBuilder
41+
* @param AttributeMetadataInterfaceFactory $attributeMetadataFactory
4142
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
4243
*/
4344
public function __construct(
4445
OptionInterfaceFactory $optionFactory,
4546
ValidationRuleInterfaceFactory $validationRuleFactory,
46-
AttributeMetadataDataBuilder $attributeMetadataBuilder,
47+
AttributeMetadataInterfaceFactory $attributeMetadataFactory,
4748
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
4849
) {
4950
$this->optionFactory = $optionFactory;
5051
$this->validationRuleFactory = $validationRuleFactory;
51-
$this->_attributeMetadataBuilder = $attributeMetadataBuilder;
52+
$this->attributeMetadataFactory = $attributeMetadataFactory;
5253
$this->dataObjectHelper = $dataObjectHelper;
5354
}
5455

@@ -87,24 +88,23 @@ public function createMetadataAttribute($attribute)
8788
$validationRules[] = $validationRule;
8889
}
8990

90-
$this->_attributeMetadataBuilder->setAttributeCode($attribute->getAttributeCode())
91+
92+
return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())
9193
->setFrontendInput($attribute->getFrontendInput())
9294
->setInputFilter((string)$attribute->getInputFilter())
9395
->setStoreLabel($attribute->getStoreLabel())
9496
->setValidationRules($validationRules)
95-
->setVisible((boolean)$attribute->getIsVisible())
96-
->setRequired((boolean)$attribute->getIsRequired())
97+
->setIsVisible((boolean)$attribute->getIsVisible())
98+
->setIsRequired((boolean)$attribute->getIsRequired())
9799
->setMultilineCount((int)$attribute->getMultilineCount())
98100
->setDataModel((string)$attribute->getDataModel())
99101
->setOptions($options)
100102
->setFrontendClass($attribute->getFrontend()->getClass())
101103
->setFrontendLabel($attribute->getFrontendLabel())
102104
->setNote((string)$attribute->getNote())
103-
->setSystem((boolean)$attribute->getIsSystem())
104-
->setUserDefined((boolean)$attribute->getIsUserDefined())
105+
->setIsSystem((boolean)$attribute->getIsSystem())
106+
->setIsUserDefined((boolean)$attribute->getIsUserDefined())
105107
->setBackendType($attribute->getBackendType())
106108
->setSortOrder((int)$attribute->getSortOrder());
107-
108-
return $this->_attributeMetadataBuilder->create();
109109
}
110110
}

dev/tests/integration/testsuite/Magento/Customer/Api/AddressRepositoryTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ protected function setUp()
5555
->setCity('CityM')
5656
->setFirstname('John')
5757
->setLastname('Smith')
58-
->setCompany('CompanyName');
58+
->setCompany('CompanyName')
59+
->setCustomAttributes([]);
5960

6061
/* XXX: would it be better to have a clear method for this? */
6162
$address2 = $this->_addressFactory->create()
@@ -68,7 +69,8 @@ protected function setUp()
6869
->setCity('CityX')
6970
->setTelephone('3234676')
7071
->setFirstname('John')
71-
->setLastname('Smith');
72+
->setLastname('Smith')
73+
->setCustomAttributes([]);
7274

7375
$this->_expectedAddresses = [$address, $address2];
7476
}
@@ -111,7 +113,7 @@ public function testSaveAddressChanges()
111113
*/
112114
public function testSaveAddressesIdSetButNotAlreadyExisting()
113115
{
114-
$proposedAddress = $this->_createSecondAddressBuilder()->setId(4200);
116+
$proposedAddress = $this->_createSecondAddress()->setId(4200);
115117
$this->repository->save($proposedAddress);
116118
}
117119

@@ -145,7 +147,7 @@ public function testGetAddressByIdBadAddressId()
145147
*/
146148
public function testSaveNewAddress()
147149
{
148-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(1);
150+
$proposedAddress = $this->_createSecondAddress()->setCustomerId(1);
149151

150152
$returnedAddress = $this->repository->save($proposedAddress);
151153
$this->assertNotNull($returnedAddress->getId());
@@ -209,7 +211,7 @@ public function testSaveNewInvalidAddress()
209211

210212
public function testSaveAddressesCustomerIdNotExist()
211213
{
212-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(4200);
214+
$proposedAddress = $this->_createSecondAddress()->setCustomerId(4200);
213215
try {
214216
$this->repository->save($proposedAddress);
215217
$this->fail('Expected exception not thrown');
@@ -220,7 +222,7 @@ public function testSaveAddressesCustomerIdNotExist()
220222

221223
public function testSaveAddressesCustomerIdInvalid()
222224
{
223-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId('this_is_not_a_valid_id');
225+
$proposedAddress = $this->_createSecondAddress()->setCustomerId('this_is_not_a_valid_id');
224226
try {
225227
$this->repository->save($proposedAddress);
226228
$this->fail('Expected exception not thrown');
@@ -403,7 +405,7 @@ private function _createFirstAddress()
403405
*
404406
* @return \Magento\Customer\Api\Data\AddressInterface
405407
*/
406-
private function _createSecondAddressBuilder()
408+
private function _createSecondAddress()
407409
{
408410
$address = $this->_addressFactory->create();
409411
$this->dataObjectHelper->mergeDataObjects(

dev/tests/integration/testsuite/Magento/Customer/Model/Resource/AddressRepositoryTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ protected function setUp()
5656
->setCity('CityM')
5757
->setFirstname('John')
5858
->setLastname('Smith')
59-
->setCompany('CompanyName');
59+
->setCompany('CompanyName')
60+
->setCustomAttributes([]);
6061
$address2 = $this->_addressFactory->create()
6162
->setId('2')
6263
->setCountryId('US')
@@ -67,7 +68,8 @@ protected function setUp()
6768
->setCity('CityX')
6869
->setTelephone('3234676')
6970
->setFirstname('John')
70-
->setLastname('Smith');
71+
->setLastname('Smith')
72+
->setCustomAttributes([]);
7173

7274
$this->_expectedAddresses = [$address, $address2];
7375
}
@@ -111,7 +113,7 @@ public function testSaveAddressChanges()
111113
*/
112114
public function testSaveAddressesIdSetButNotAlreadyExisting()
113115
{
114-
$proposedAddress = $this->_createSecondAddressBuilder()->setId(4200);
116+
$proposedAddress = $this->_createSecondAddress()->setId(4200);
115117
$this->repository->save($proposedAddress);
116118
}
117119

@@ -145,7 +147,7 @@ public function testGetAddressByIdBadAddressId()
145147
*/
146148
public function testSaveNewAddress()
147149
{
148-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(1);
150+
$proposedAddress = $this->_createSecondAddress()->setCustomerId(1);
149151

150152
$returnedAddress = $this->repository->save($proposedAddress);
151153
$this->assertNotNull($returnedAddress->getId());
@@ -209,7 +211,7 @@ public function testSaveNewInvalidAddress()
209211

210212
public function testSaveAddressesCustomerIdNotExist()
211213
{
212-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId(4200);
214+
$proposedAddress = $this->_createSecondAddress()->setCustomerId(4200);
213215
try {
214216
$this->repository->save($proposedAddress);
215217
$this->fail('Expected exception not thrown');
@@ -220,7 +222,7 @@ public function testSaveAddressesCustomerIdNotExist()
220222

221223
public function testSaveAddressesCustomerIdInvalid()
222224
{
223-
$proposedAddress = $this->_createSecondAddressBuilder()->setCustomerId('this_is_not_a_valid_id');
225+
$proposedAddress = $this->_createSecondAddress()->setCustomerId('this_is_not_a_valid_id');
224226
try {
225227
$this->repository->save($proposedAddress);
226228
$this->fail('Expected exception not thrown');
@@ -403,7 +405,7 @@ private function _createFirstAddress()
403405
*
404406
* @return \Magento\Customer\Api\Data\AddressInterface
405407
*/
406-
private function _createSecondAddressBuilder()
408+
private function _createSecondAddress()
407409
{
408410
$address = $this->_addressFactory->create();
409411
$this->dataObjectHelper->mergeDataObjects(

dev/tests/unit/testsuite/Magento/Framework/Api/DataObjectHelperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ public function testMergeDataObjects($data1, $data2)
261261

262262
$firstRegionDataObject->setRegionId($data1['region']['region_id']);
263263
$firstRegionDataObject->setRegion($data1['region']['region']);
264-
if(isset($data1['id'])) {
264+
if (isset($data1['id'])) {
265265
$firstAddressDataObject->setId($data1['id']);
266266
}
267-
if(isset($data1['country_id'])) {
267+
if (isset($data1['country_id'])) {
268268
$firstAddressDataObject->setCountryId($data1['country_id']);
269269
}
270270
$firstAddressDataObject->setStreet($data1['street']);
@@ -288,10 +288,10 @@ public function testMergeDataObjects($data1, $data2)
288288

289289
$secondRegionDataObject->setRegionId($data2['region']['region_id']);
290290
$secondRegionDataObject->setRegion($data2['region']['region']);
291-
if(isset($data2['id'])) {
291+
if (isset($data2['id'])) {
292292
$secondAddressDataObject->setId($data2['id']);
293293
}
294-
if(isset($data2['country_id'])) {
294+
if (isset($data2['country_id'])) {
295295
$secondAddressDataObject->setCountryId($data2['country_id']);
296296
}
297297
$secondAddressDataObject->setStreet($data2['street']);

0 commit comments

Comments
 (0)