<?php declare(strict_types=1);
namespace Cytrus\Import\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
class CustomerGroupSubscriber implements EventSubscriberInterface
{
private EntityRepository $customerRepository;
public function __construct(EntityRepository $customerRepository)
{
$this->customerRepository = $customerRepository;
}
public static function getSubscribedEvents(): array
{
return [
CustomerRegisterEvent::class => 'onCustomerRegister',
];
}
public function onCustomerRegister(CustomerRegisterEvent $event): void
{
$customer = $event->getCustomer();
$customerId = $customer->getId();
$groupId = $_REQUEST['customerType'] ?? null;
if ($groupId) {
$this->customerRepository->update([
[
'id' => $customerId,
'groupId' => $groupId,
# muss in abhängigkeit von der kundengruppe gesetzt werden
#'defaultPaymentMethodId' => '7b85d4b1c52a44b980859fd7b7358929',
]
], $event->getContext());
}
}
}