Skip to content

Commit 4a6b81f

Browse files
author
Stanislav Idolov
authored
🔃 [EngCom] Public Pull Requests - 2.2-develop
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
2 parents 06274cb + 6253bac commit 4a6b81f

File tree

6 files changed

+14
-34
lines changed

6 files changed

+14
-34
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,14 @@ public function execute()
222222
$data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType(
223223
$data['frontend_input']
224224
);
225+
226+
if ($model->getIsUserDefined() === null) {
227+
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
228+
}
225229
}
226230

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

229-
if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {
230-
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
231-
}
232-
233233
$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
234234
if ($defaultValueField) {
235235
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);

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 & 7 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
*

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)