vendor/shopware/core/Content/Flow/Dispatching/Action/ChangeCustomerGroupAction.php line 39

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Flow\Dispatching\Action;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  4. use Shopware\Core\Framework\Event\CustomerAware;
  5. use Shopware\Core\Framework\Event\DelayAware;
  6. use Shopware\Core\Framework\Event\FlowEvent;
  7. class ChangeCustomerGroupAction extends FlowAction
  8. {
  9.     private EntityRepositoryInterface $customerRepository;
  10.     /**
  11.      * @internal
  12.      */
  13.     public function __construct(EntityRepositoryInterface $customerRepository)
  14.     {
  15.         $this->customerRepository $customerRepository;
  16.     }
  17.     public static function getName(): string
  18.     {
  19.         return 'action.change.customer.group';
  20.     }
  21.     public static function getSubscribedEvents(): array
  22.     {
  23.         return [
  24.             self::getName() => 'handle',
  25.         ];
  26.     }
  27.     public function requirements(): array
  28.     {
  29.         return [CustomerAware::class, DelayAware::class];
  30.     }
  31.     public function handle(FlowEvent $event): void
  32.     {
  33.         $config $event->getConfig();
  34.         if (!\array_key_exists('customerGroupId'$config)) {
  35.             return;
  36.         }
  37.         $customerGroupId $config['customerGroupId'];
  38.         $baseEvent $event->getEvent();
  39.         if (!$baseEvent instanceof CustomerAware || empty($customerGroupId)) {
  40.             return;
  41.         }
  42.         $this->customerRepository->update([
  43.             [
  44.                 'id' => $baseEvent->getCustomerId(),
  45.                 'groupId' => $customerGroupId,
  46.             ],
  47.         ], $baseEvent->getContext());
  48.     }
  49. }