custom/plugins/CytrusImport/src/Subscriber/CustomerGroupSubscriber.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cytrus\Import\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  6. class CustomerGroupSubscriber implements EventSubscriberInterface
  7. {
  8.     
  9.     private EntityRepository $customerRepository;
  10.     public function __construct(EntityRepository $customerRepository)
  11.     {
  12.         $this->customerRepository = $customerRepository;
  13.     }
  14.     
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             CustomerRegisterEvent::class => 'onCustomerRegister',
  19.         ];
  20.     }
  21.     public function onCustomerRegister(CustomerRegisterEvent $event): void
  22.     {
  23.         $customer = $event->getCustomer();
  24.         $customerId = $customer->getId();
  25.         $groupId = $_REQUEST['customerType'] ?? null;
  26.         if ($groupId) {
  27.             $this->customerRepository->update([
  28.                 [
  29.                     'id' => $customerId,
  30.                     'groupId' => $groupId,
  31.                     # muss in abhängigkeit von der kundengruppe gesetzt werden
  32.                     #'defaultPaymentMethodId' => '7b85d4b1c52a44b980859fd7b7358929',
  33.                 ]
  34.             ], $event->getContext());
  35.         }
  36.     }
  37. }