I have a simple observer that sets the customer group id to a custom group id on customer_register_success.
$customer = $observer->getEvent()->getCustomer(); $customer->setGroupId($customGroupId); $this->_customerRepositoryInterface->save($customer);
The problem is because I'm calling the save function in observer its firing the it twice.
The issue with this is the newsletter subscribe function is getting fired twice with different results setting it the status to 1 and and the next one to 3. And if I call setGroupId and don't save and continue on it doesn't change the groupId of the customer.
How do I got about saving the groupId on account creation?
Solved! Go to Solution.
Try to set is_subscribed as well
$customer = $observer->getEvent()->getCustomer();
$isSubscribed = $observer->getEvent()->getAccountController()->getRequest()->getParam('is_subscribed');
$customer->getExtensionAttributes()->setIsSubscribed($isSubscribed);
$customer->setGroupId($customGroupId);
$this->_customerRepositoryInterface->save($customer);
Try to set is_subscribed as well
$customer = $observer->getEvent()->getCustomer();
$isSubscribed = $observer->getEvent()->getAccountController()->getRequest()->getParam('is_subscribed');
$customer->getExtensionAttributes()->setIsSubscribed($isSubscribed);
$customer->setGroupId($customGroupId);
$this->_customerRepositoryInterface->save($customer);
Brilliant! Exactly what I was looking for.