Skip to content

Commit 9707676

Browse files
Thundargelanivishal
authored andcommitted
Issue 12479 refactor, attribute_set_id always not null on customer
1 parent ce82c5c commit 9707676

File tree

5 files changed

+10
-44
lines changed

5 files changed

+10
-44
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
@@ -359,13 +359,6 @@ public function updateData($customer)
359359
$this->setId($customerId);
360360
}
361361

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

@@ -961,6 +954,16 @@ public function getSharedWebsiteIds()
961954
return $ids;
962955
}
963956

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

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

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ public function save(CustomerInterface $customer, $passwordHash = null)
194194
if ($storeId === null) {
195195
$customerModel->setStoreId($this->storeManager->getStore()->getId());
196196
}
197-
// Need to use attribute set or future updates can cause data loss
198-
if (!$customerModel->getAttributeSetId()) {
199-
$customerModel->setAttributeSetId(CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
200-
}
201197
$this->populateCustomerWithSecureData($customerModel, $passwordHash);
202198
// If customer email was changed, reset RpToken info
203199
if ($prevCustomerData && $prevCustomerData->getEmail() !== $customerModel->getEmail()) {

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)