<?php
namespace CioRegistrationFormExtension\Subscriber;
use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class RegistrationSubscriber implements EventSubscriberInterface
{
private ContainerInterface $container;
private RequestStack $requestStack;
public function __construct(ContainerInterface $container, RequestStack $requestStack)
{
$this->container = $container;
$this->requestStack = $requestStack;
}
public static function getSubscribedEvents()
{
return [
CustomerRegisterEvent::class => 'onCustomerRegisterEvent'
];
}
public function onCustomerRegisterEvent(CustomerRegisterEvent $event)
{
/** @var EntityRepositoryInterface $customerRepository */
$customerRepository = $this->container->get('customer.repository');
$request = $this->requestStack->getCurrentRequest();
$customer = [
'id' => $event->getCustomerId(),
'customFields' => [
'custom_customer_itpnumber' => $request->get('cioCustomItpnumber', '')
]
];
$customerRepository->update([$customer], $event->getContext());
}
}