17
17
use Magento \Customer \Model \Data \CustomerSecureFactory ;
18
18
use Magento \Customer \Model \Delegation \Data \NewOperation ;
19
19
use Magento \Customer \Model \Delegation \Storage as DelegatedStorage ;
20
+ use Magento \Customer \Model \ResourceModel \Customer \Collection ;
20
21
use Magento \Framework \Api \DataObjectHelper ;
21
22
use Magento \Framework \Api \ExtensibleDataObjectConverter ;
22
23
use Magento \Framework \Api \ExtensionAttribute \JoinProcessorInterface ;
31
32
/**
32
33
* Customer repository.
33
34
*
35
+ * CRUD operations for customer entity
36
+ *
34
37
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
35
38
* @SuppressWarnings(PHPMD.TooManyFields)
36
39
*/
@@ -187,8 +190,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
187
190
{
188
191
/** @var NewOperation|null $delegatedNewOperation */
189
192
$ delegatedNewOperation = !$ customer ->getId () ? $ this ->delegatedStorage ->consumeNewOperation () : null ;
190
- $ prevCustomerData = null ;
191
- $ prevCustomerDataArr = null ;
193
+ $ prevCustomerData = $ prevCustomerDataArr = null ;
192
194
if ($ customer ->getId ()) {
193
195
$ prevCustomerData = $ this ->getById ($ customer ->getId ());
194
196
$ prevCustomerDataArr = $ prevCustomerData ->__toArray ();
@@ -214,6 +216,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
214
216
$ prevCustomerData ? $ prevCustomerData ->getStoreId () : $ this ->storeManager ->getStore ()->getId ()
215
217
);
216
218
}
219
+ $ this ->setCustomerGroupId ($ customerModel , $ customerArr , $ prevCustomerDataArr );
217
220
// Need to use attribute set or future updates can cause data loss
218
221
if (!$ customerModel ->getAttributeSetId ()) {
219
222
$ customerModel ->setAttributeSetId (CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER );
@@ -452,4 +455,18 @@ private function setValidationFlag($customerArray, $customerModel)
452
455
$ customerModel ->setData ('ignore_validation_flag ' , true );
453
456
}
454
457
}
458
+
459
+ /**
460
+ * Set customer group id
461
+ *
462
+ * @param Customer $customerModel
463
+ * @param array $customerArr
464
+ * @param array $prevCustomerDataArr
465
+ */
466
+ private function setCustomerGroupId ($ customerModel , $ customerArr , $ prevCustomerDataArr )
467
+ {
468
+ if (!isset ($ customerArr ['group_id ' ]) && $ prevCustomerDataArr && isset ($ prevCustomerDataArr ['group_id ' ])) {
469
+ $ customerModel ->setGroupId ($ prevCustomerDataArr ['group_id ' ]);
470
+ }
471
+ }
455
472
}
0 commit comments