Skip to content

Commit

Permalink
Issue 12479 refactor, attribute_set_id always not null on customer an…
Browse files Browse the repository at this point in the history
…d customer address
  • Loading branch information
Thundar committed Oct 3, 2018
1 parent 44fe03f commit 6a098a7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 46 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
33 changes: 10 additions & 23 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 Expand Up @@ -1051,22 +1054,6 @@ public function beforeDelete()
return parent::beforeDelete();
}

/**
* Processing object before save data
*
* @return $this
*/
public function beforeSave()
{
// Need to use attribute set or future updates can cause data loss
if (!$this->getAttributeSetId()) {
$this->setAttributeSetId(
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
);
}
return parent::beforeSave();
}

/**
* Processing object after save data
*
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 6a098a7

Please sign in to comment.