<?php declare(strict_types=1);
namespace Dvdw\PlatformChoice\Checkout\Customer\Subscriber;
use Shopware\Core\Checkout\Customer\CustomerEvents;
use Shopware\Core\Framework\Event\DataMappingEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RegisterDataMappingSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): iterable
{
return [CustomerEvents::MAPPING_REGISTER_CUSTOMER => 'updateCustomerGroup'];
}
public function updateCustomerGroup(DataMappingEvent $event): void
{
$customer = $event->getOutput();
$bag = $event->getInput();
if (!isset($customer['groupId']) || ($groupId = $bag->get('groupId')) === null) {
return;
}
$customer['groupId'] = $groupId;
$event->setOutput($customer);
}
}