Skip to content

Commit

Permalink
ENGCOM-3082: Fix Customer custom attributes lost after save #17968
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Oct 12, 2018
2 parents 52de41c + e3b9909 commit 6253bac
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
3 changes: 0 additions & 3 deletions app/code/Magento/Customer/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public function updateData(AddressInterface $address)
// Need to explicitly set this due to discrepancy in the keys between model and data object
$this->setIsDefaultBilling($address->isDefaultBilling());
$this->setIsDefaultShipping($address->isDefaultShipping());
if (!$this->getAttributeSetId()) {
$this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
}
$customAttributes = $address->getCustomAttributes();
if ($customAttributes !== null) {
foreach ($customAttributes as $attribute) {
Expand Down
17 changes: 10 additions & 7 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,6 @@ public function updateData($customer)
$this->setId($customerId);
}

// Need to use attribute set or future updates can cause data loss
if (!$this->getAttributeSetId()) {
$this->setAttributeSetId(
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
);
}

return $this;
}

Expand Down Expand Up @@ -960,6 +953,16 @@ public function getSharedWebsiteIds()
return $ids;
}

/**
* Retrieve attribute set id for customer.
*
* @return int
*/
public function getAttributeSetId()
{
return parent::getAttributeSetId() ?: CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
}

/**
* Set store to customer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
$customerModel->setStoreId($this->storeManager->getStore()->getId());
}

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

// If customer email was changed, reset RpToken info
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ public function testUpdateData()
}
$expectedResult[$attribute->getAttributeCode()] = $attribute->getValue();
$expectedResult['attribute_set_id'] =
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
$this->assertEquals($this->_model->getData(), $expectedResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ public function testSave()
$customerModel->expects($this->once())
->method('setId')
->with($customerId);
$customerModel->expects($this->once())
->method('getAttributeSetId')
->willReturn(null);
$customerModel->expects($this->once())
->method('setAttributeSetId')
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
$customerAttributesMetaData->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
Expand Down Expand Up @@ -616,12 +610,6 @@ public function testSaveWithPasswordHash()
$customerModel->expects($this->once())
->method('setId')
->with($customerId);
$customerModel->expects($this->once())
->method('getAttributeSetId')
->willReturn(null);
$customerModel->expects($this->once())
->method('setAttributeSetId')
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
$customerModel->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
Expand Down

0 comments on commit 6253bac

Please sign in to comment.