Skip to content

Commit f520001

Browse files
🔃 [EngCom] Public Pull Requests - 2.1-develop
Accepted Public Pull Requests: - #14757: Preserve user group id when using /V1/customers/:customerId (PUT) (by @ferrazzuk) Fixed GitHub Issues: - #14663: Updating Customer through rest/all/V1/customers/:id resets group_id if group_id not passed in payload (reported by @abancroft0) has been fixed in #14757 by @ferrazzuk in 2.1-develop branch Related commits: 1. 51f2f07
2 parents 7f085a5 + eab5058 commit f520001

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
186186
$customerModel->setRpTokenCreatedAt(null);
187187
}
188188

189+
// Set group id to current stored id if no group id passed.
190+
if (!($prevCustomerData === null) && $prevCustomerData->getGroupId() && $customer->getGroupId() === null) {
191+
$customerModel->setGroupId(
192+
$prevCustomerData->getGroupId()
193+
);
194+
}
195+
189196
$this->setDefaultBilling($customerArr, $prevCustomerDataArr, $customerModel);
190197

191198
$this->setDefaultShipping($customerArr, $prevCustomerDataArr, $customerModel);

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function setUp()
160160
false
161161
);
162162
$this->customer = $this->getMockBuilder(\Magento\Customer\Api\Data\CustomerInterface::class)
163-
->setMethods(['__toArray'])
163+
->setMethods(['__toArray', 'setGroupId'])
164164
->disableOriginalConstructor()
165165
->getMockForAbstractClass();
166166
$this->model = new \Magento\Customer\Model\ResourceModel\CustomerRepository(
@@ -187,6 +187,7 @@ public function testSave()
187187
{
188188
$customerId = 1;
189189
$storeId = 2;
190+
$groupId = 1;
190191

191192
$region = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\RegionInterface::class, [], '', false);
192193
$address = $this->getMockForAbstractClass(
@@ -222,6 +223,7 @@ public function testSave()
222223
[
223224
'getId',
224225
'setId',
226+
'setGroupId',
225227
'setStoreId',
226228
'getStoreId',
227229
'getAttributeSetId',
@@ -254,7 +256,8 @@ public function testSave()
254256
'getEmail',
255257
'getWebsiteId',
256258
'getAddresses',
257-
'setAddresses'
259+
'setAddresses',
260+
'getGroupId'
258261
]
259262
);
260263
$customerSecureData = $this->getMock(
@@ -289,6 +292,17 @@ public function testSave()
289292
->method('setCustomerId')
290293
->with($customerId)
291294
->willReturnSelf();
295+
296+
$this->customer->expects($this->exactly(2))
297+
->method('getGroupId')
298+
->willReturn($groupId);
299+
$customerAttributesMetaData->expects($this->once())
300+
->method('getGroupId')
301+
->willReturn(null);
302+
$customerModel->expects($this->once())
303+
->method('setGroupId')
304+
->with($groupId);
305+
292306
$address->expects($this->once())
293307
->method('getRegion')
294308
->willReturn($region);

0 commit comments

Comments
 (0)