custom/plugins/FourtwosixThemeCustomization/src/Subscriber/RegisterSubscriber.php line 35

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace FourtwosixThemeCustomization\Subscriber;
  4. use FourtwosixThemeCustomization\FourtwosixThemeCustomization as Plugin;
  5. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  6. use Shopware\Core\Checkout\Customer\Event\GuestCustomerRegisterEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. use Doctrine\DBAL\Connection;
  10. class RegisterSubscriber implements EventSubscriberInterface
  11. {
  12.     private EntityRepositoryInterface $customerRepository;
  13.     private Connection $dbConnection;
  14.     public function __construct(EntityRepositoryInterface $customerRepositoryConnection $dbConnection)
  15.     {
  16.         $this->customerRepository $customerRepository;
  17.         $this->dbConnection $dbConnection;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             CustomerRegisterEvent::class => 'onRegister',
  23.             GuestCustomerRegisterEvent::class => 'onRegister'
  24.         ];
  25.     }
  26.     public function onRegister(CustomerRegisterEvent|GuestCustomerRegisterEvent $event) {
  27.         if(!empty($event->getCustomer())) {
  28.             $sql "UPDATE `customer` SET `customer_group_id` = UNHEX('".Plugin::REGISTERED_CUSTOMER_GROUP_ID."') WHERE `id`= UNHEX('".$event->getCustomer()->getId()."')";
  29.             $this->dbConnection->executeStatement($sql);
  30.         }
  31.     }
  32. }