Skip to content

Commit 6a098a7

Browse files
committed
Issue 12479 refactor, attribute_set_id always not null on customer and customer address
1 parent 44fe03f commit 6a098a7

File tree

5 files changed

+10
-46
lines changed

5 files changed

+10
-46
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ public function updateData(AddressInterface $address)
154154
// Need to explicitly set this due to discrepancy in the keys between model and data object
155155
$this->setIsDefaultBilling($address->isDefaultBilling());
156156
$this->setIsDefaultShipping($address->isDefaultShipping());
157-
if (!$this->getAttributeSetId()) {
158-
$this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
159-
}
160157
$customAttributes = $address->getCustomAttributes();
161158
if ($customAttributes !== null) {
162159
foreach ($customAttributes as $attribute) {

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,6 @@ public function updateData($customer)
358358
$this->setId($customerId);
359359
}
360360

361-
// Need to use attribute set or future updates can cause data loss
362-
if (!$this->getAttributeSetId()) {
363-
$this->setAttributeSetId(
364-
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
365-
);
366-
}
367-
368361
return $this;
369362
}
370363

@@ -960,6 +953,16 @@ public function getSharedWebsiteIds()
960953
return $ids;
961954
}
962955

956+
/**
957+
* Retrieve attribute set id for customer.
958+
*
959+
* @return int
960+
*/
961+
public function getAttributeSetId()
962+
{
963+
return parent::getAttributeSetId() ?: CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
964+
}
965+
963966
/**
964967
* Set store to customer
965968
*
@@ -1051,22 +1054,6 @@ public function beforeDelete()
10511054
return parent::beforeDelete();
10521055
}
10531056

1054-
/**
1055-
* Processing object before save data
1056-
*
1057-
* @return $this
1058-
*/
1059-
public function beforeSave()
1060-
{
1061-
// Need to use attribute set or future updates can cause data loss
1062-
if (!$this->getAttributeSetId()) {
1063-
$this->setAttributeSetId(
1064-
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
1065-
);
1066-
}
1067-
return parent::beforeSave();
1068-
}
1069-
10701057
/**
10711058
* Processing object after save data
10721059
*

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,6 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
205205
$customerModel->setStoreId($this->storeManager->getStore()->getId());
206206
}
207207

208-
// Need to use attribute set or future updates can cause data loss
209-
if (!$customerModel->getAttributeSetId()) {
210-
$customerModel->setAttributeSetId(
211-
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
212-
);
213-
}
214208
$this->populateCustomerWithSecureData($customerModel, $passwordHash);
215209

216210
// If customer email was changed, reset RpToken info

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ public function testUpdateData()
307307
}
308308

309309
$expectedResult[$attribute->getAttributeCode()] = $attribute->getValue();
310-
$expectedResult['attribute_set_id'] =
311-
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
312310

313311
$this->assertEquals($this->_model->getData(), $expectedResult);
314312
}

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,6 @@ public function testSave()
334334
$customerModel->expects($this->once())
335335
->method('setId')
336336
->with($customerId);
337-
$customerModel->expects($this->once())
338-
->method('getAttributeSetId')
339-
->willReturn(null);
340-
$customerModel->expects($this->once())
341-
->method('setAttributeSetId')
342-
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
343337
$customerAttributesMetaData->expects($this->atLeastOnce())
344338
->method('getId')
345339
->willReturn($customerId);
@@ -616,12 +610,6 @@ public function testSaveWithPasswordHash()
616610
$customerModel->expects($this->once())
617611
->method('setId')
618612
->with($customerId);
619-
$customerModel->expects($this->once())
620-
->method('getAttributeSetId')
621-
->willReturn(null);
622-
$customerModel->expects($this->once())
623-
->method('setAttributeSetId')
624-
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
625613
$customerModel->expects($this->atLeastOnce())
626614
->method('getId')
627615
->willReturn($customerId);

0 commit comments

Comments
 (0)