Skip to main content
added 145 characters in body
Source Link
hungersoft
  • 447
  • 3
  • 4

The above code is going to create an infinite loop, because every time the customer is saved the event will be triggered and the observer will keep executing until it crashes.

Adding a stop condition should fix the issue:

$groupId = $this->_request->getParam('groupId');    
if ($groupId !== $customer->getGroupId()) {
    $customer->setGroupId($groupId);    
    $this->customerRepository->save($customer);    
}

Alternatively, you can also use this extension: Customer group selector [M2]

The above code is going to create an infinite loop, because every time the customer is saved the event will be triggered and the observer will keep executing until it crashes.

Adding a stop condition should fix the issue:

$groupId = $this->_request->getParam('groupId');    
if ($groupId !== $customer->getGroupId()) {
    $customer->setGroupId($groupId);    
    $this->customerRepository->save($customer);    
}

The above code is going to create an infinite loop, because every time the customer is saved the event will be triggered and the observer will keep executing until it crashes.

Adding a stop condition should fix the issue:

$groupId = $this->_request->getParam('groupId');    
if ($groupId !== $customer->getGroupId()) {
    $customer->setGroupId($groupId);    
    $this->customerRepository->save($customer);    
}

Alternatively, you can also use this extension: Customer group selector [M2]

Source Link
hungersoft
  • 447
  • 3
  • 4

The above code is going to create an infinite loop, because every time the customer is saved the event will be triggered and the observer will keep executing until it crashes.

Adding a stop condition should fix the issue:

$groupId = $this->_request->getParam('groupId');    
if ($groupId !== $customer->getGroupId()) {
    $customer->setGroupId($groupId);    
    $this->customerRepository->save($customer);    
}