<?php
declare(strict_types=1);
namespace FourtwosixThemeCustomization\Subscriber;
use FourtwosixThemeCustomization\FourtwosixThemeCustomization as Plugin;
use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
use Shopware\Core\Checkout\Customer\Event\GuestCustomerRegisterEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Doctrine\DBAL\Connection;
class RegisterSubscriber implements EventSubscriberInterface
{
private EntityRepositoryInterface $customerRepository;
private Connection $dbConnection;
public function __construct(EntityRepositoryInterface $customerRepository, Connection $dbConnection)
{
$this->customerRepository = $customerRepository;
$this->dbConnection = $dbConnection;
}
public static function getSubscribedEvents(): array
{
return [
CustomerRegisterEvent::class => 'onRegister',
GuestCustomerRegisterEvent::class => 'onRegister'
];
}
public function onRegister(CustomerRegisterEvent|GuestCustomerRegisterEvent $event) {
if(!empty($event->getCustomer())) {
$sql = "UPDATE `customer` SET `customer_group_id` = UNHEX('".Plugin::REGISTERED_CUSTOMER_GROUP_ID."') WHERE `id`= UNHEX('".$event->getCustomer()->getId()."')";
$this->dbConnection->executeStatement($sql);
}
}
}