Skip to content

Commit c5c5f39

Browse files
authored
ENGCOM-5728: group_id overridden if set #23764
2 parents 4083d7c + 65634c0 commit c5c5f39

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

app/code/Magento/Customer/Model/CustomerExtractor.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
6+
77
namespace Magento\Customer\Model;
88

99
use Magento\Customer\Api\CustomerMetadataInterface;
1010
use Magento\Customer\Api\Data\CustomerInterface;
1111
use Magento\Customer\Api\GroupManagementInterface;
1212
use Magento\Framework\App\RequestInterface;
1313

14+
/**
15+
* Customer Extractor model.
16+
*/
1417
class CustomerExtractor
1518
{
1619
/**
@@ -60,6 +63,8 @@ public function __construct(
6063
}
6164

6265
/**
66+
* Creates a Customer object populated with the given form code and request data.
67+
*
6368
* @param string $formCode
6469
* @param RequestInterface $request
6570
* @param array $attributeValues
@@ -80,23 +85,26 @@ public function extract(
8085
$customerData = $customerForm->compactData($customerData);
8186

8287
$allowedAttributes = $customerForm->getAllowedAttributes();
83-
$isGroupIdEmpty = isset($allowedAttributes['group_id']);
88+
$isGroupIdEmpty = !isset($allowedAttributes['group_id']);
8489

8590
$customerDataObject = $this->customerFactory->create();
8691
$this->dataObjectHelper->populateWithArray(
8792
$customerDataObject,
8893
$customerData,
8994
\Magento\Customer\Api\Data\CustomerInterface::class
9095
);
96+
9197
$store = $this->storeManager->getStore();
98+
$storeId = $store->getId();
99+
92100
if ($isGroupIdEmpty) {
93101
$customerDataObject->setGroupId(
94-
$this->customerGroupManagement->getDefaultGroup($store->getId())->getId()
102+
$this->customerGroupManagement->getDefaultGroup($storeId)->getId()
95103
);
96104
}
97105

98106
$customerDataObject->setWebsiteId($store->getWebsiteId());
99-
$customerDataObject->setStoreId($store->getId());
107+
$customerDataObject->setStoreId($storeId);
100108

101109
return $customerDataObject;
102110
}

app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Customer\Test\Unit\Model;
78

89
use Magento\Customer\Model\CustomerExtractor;
910

11+
/**
12+
* Unit test CustomerExtractorTest
13+
*/
1014
class CustomerExtractorTest extends \PHPUnit\Framework\TestCase
1115
{
1216
/** @var CustomerExtractor */
@@ -137,19 +141,9 @@ public function testExtract()
137141
$this->storeManager->expects($this->once())
138142
->method('getStore')
139143
->willReturn($this->store);
140-
$this->store->expects($this->exactly(2))
141-
->method('getId')
142-
->willReturn(1);
143-
$this->customerGroupManagement->expects($this->once())
144-
->method('getDefaultGroup')
145-
->with(1)
146-
->willReturn($this->customerGroup);
147-
$this->customerGroup->expects($this->once())
144+
$this->store->expects($this->once())
148145
->method('getId')
149146
->willReturn(1);
150-
$this->customerData->expects($this->once())
151-
->method('setGroupId')
152-
->with(1);
153147
$this->store->expects($this->once())
154148
->method('getWebsiteId')
155149
->willReturn(1);

0 commit comments

Comments
 (0)