Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #18196: Fix for custom product attribute changing 'backend_type' when 'is_user_defined = 1' and get updated/saved in Admin Backend (by @bartoszkubicki)
 - #17968: Fix Customer custom attributes lost after save (by @Thundar)


Fixed GitHub Issues:
 - #9219: Custom Product Attribute changes 'backend_type' when 'is_user_defined = 1' and get updated/saved in Admin Backend (reported by @mhauri) has been fixed in #18196 by @bartoszkubicki in 2.2-develop branch
   Related commits:
     1. f6a9459

 - #12479: Saving Customer Model directly causes loss of data (reported by @Danielc3) has been fixed in #17968 by @Thundar in 2.2-develop branch
   Related commits:
     1. 7965c9b
     2. 44fe03f
     3. 6a098a7
  • Loading branch information
Stanislav Idolov authored Oct 12, 2018
2 parents 06274cb + 6253bac commit 4a6b81f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ public function execute()
$data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType(
$data['frontend_input']
);

if ($model->getIsUserDefined() === null) {
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
}
}

$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];

if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
}

$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
Expand Down
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 4a6b81f

Please sign in to comment.