Skip to content

Commit 75a1797

Browse files
committed
Merge remote-tracking branch 'l3/ACP2E-203' into PR_L3_22_04_2022
2 parents 610f7f5 + 73aabd5 commit 75a1797

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ public function save(CustomerInterface $customer, $passwordHash = null)
219219
$customer->setAddresses($origAddresses);
220220
/** @var CustomerModel $customerModel */
221221
$customerModel = $this->customerFactory->create(['data' => $customerData]);
222+
$this->populateWithOrigData($customerModel, $prevCustomerDataArr);
223+
222224
//Model's actual ID field maybe different than "id" so "id" field from $customerData may be ignored.
223225
$customerModel->setId($customer->getId());
224226
$storeId = $customerModel->getStoreId();
@@ -295,6 +297,21 @@ public function save(CustomerInterface $customer, $passwordHash = null)
295297
return $savedCustomer;
296298
}
297299

300+
/**
301+
* Populate customer model with previous data
302+
*
303+
* @param CustomerModel $customerModel
304+
* @param ?array $prevCustomerDataArr
305+
*/
306+
private function populateWithOrigData(CustomerModel $customerModel, ?array $prevCustomerDataArr)
307+
{
308+
if (!empty($prevCustomerDataArr)) {
309+
foreach ($prevCustomerDataArr as $field => $value) {
310+
$customerModel->setOrigData($field, $value);
311+
}
312+
}
313+
}
314+
298315
/**
299316
* Delete addresses by ids
300317
*

app/code/Magento/Customer/Test/Unit/Model/ResourceModel/CustomerRepositoryTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,10 @@ public function testSave(): void
232232
'setFailuresNum',
233233
'setFirstFailure',
234234
'setLockExpires',
235-
'setGroupId'
235+
'setGroupId',
236236
]
237237
)
238-
->onlyMethods(['getId', 'setId', 'getAttributeSetId', 'getDataModel', 'save'])
238+
->onlyMethods(['getId', 'setId', 'getAttributeSetId', 'getDataModel', 'save', 'setOrigData'])
239239
->disableOriginalConstructor()
240240
->getMock();
241241

@@ -275,10 +275,13 @@ public function testSave(): void
275275
->willReturn($customerId);
276276
$this->customer
277277
->method('__toArray')
278-
->willReturnOnConsecutiveCalls(['group_id' => 1], []);
279-
$customerModel->expects($this->once())
280-
->method('setGroupId')
281-
->with(1);
278+
->willReturnOnConsecutiveCalls(['firstname' => 'firstname', 'group_id' => 1], []);
279+
$customerModel->expects($this->exactly(2))
280+
->method('setOrigData')
281+
->withConsecutive(
282+
['firstname', 'firstname'],
283+
['group_id', 1]
284+
);
282285
$this->customerRegistry->expects($this->atLeastOnce())
283286
->method('retrieve')
284287
->with($customerId)

0 commit comments

Comments
 (0)