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

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\FlowEvent;
  6. class ChangeCustomerGroupAction extends FlowAction
  7. {
  8.     private EntityRepositoryInterface $customerRepository;
  9.     public function __construct(EntityRepositoryInterface $customerRepository)
  10.     {
  11.         $this->customerRepository $customerRepository;
  12.     }
  13.     public static function getName(): string
  14.     {
  15.         return 'action.change.customer.group';
  16.     }
  17.     public static function getSubscribedEvents(): array
  18.     {
  19.         return [
  20.             self::getName() => 'handle',
  21.         ];
  22.     }
  23.     public function requirements(): array
  24.     {
  25.         return [CustomerAware::class];
  26.     }
  27.     public function handle(FlowEvent $event): void
  28.     {
  29.         $config $event->getConfig();
  30.         if (!\array_key_exists('customerGroupId'$config)) {
  31.             return;
  32.         }
  33.         $customerGroupId $config['customerGroupId'];
  34.         $baseEvent $event->getEvent();
  35.         if (!$baseEvent instanceof CustomerAware || empty($customerGroupId)) {
  36.             return;
  37.         }
  38.         $this->customerRepository->update([
  39.             [
  40.                 'id' => $baseEvent->getCustomerId(),
  41.                 'groupId' => $customerGroupId,
  42.             ],
  43.         ], $baseEvent->getContext());
  44.     }
  45. }