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

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Content\Flow\Dispatching\Action;
  3. use Shopware\Core\Content\Flow\Dispatching\DelayableAction;
  4. use Shopware\Core\Content\Flow\Dispatching\StorableFlow;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  7. use Shopware\Core\Framework\Event\CustomerAware;
  8. use Shopware\Core\Framework\Event\FlowEvent;
  9. use Shopware\Core\Framework\Feature;
  10. /**
  11.  * @deprecated tag:v6.5.0 - reason:remove-subscriber - FlowActions won't be executed over the event system anymore,
  12.  * therefore the actions won't implement the EventSubscriberInterface anymore.
  13.  */
  14. class ChangeCustomerGroupAction extends FlowAction implements DelayableAction
  15. {
  16.     private EntityRepositoryInterface $customerRepository;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(EntityRepositoryInterface $customerRepository)
  21.     {
  22.         $this->customerRepository $customerRepository;
  23.     }
  24.     public static function getName(): string
  25.     {
  26.         return 'action.change.customer.group';
  27.     }
  28.     /**
  29.      * @deprecated tag:v6.5.0 - reason:remove-subscriber - Will be removed
  30.      */
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         if (Feature::isActive('v6.5.0.0')) {
  34.             return [];
  35.         }
  36.         return [
  37.             self::getName() => 'handle',
  38.         ];
  39.     }
  40.     /**
  41.      * @return array<int, string>
  42.      */
  43.     public function requirements(): array
  44.     {
  45.         return [CustomerAware::class];
  46.     }
  47.     /**
  48.      * @deprecated tag:v6.5.0 Will be removed, implement handleFlow instead
  49.      */
  50.     public function handle(FlowEvent $event): void
  51.     {
  52.         Feature::triggerDeprecationOrThrow(
  53.             'v6.5.0.0',
  54.             Feature::deprecatedMethodMessage(__CLASS____METHOD__'v6.5.0.0')
  55.         );
  56.         $baseEvent $event->getEvent();
  57.         if (!$baseEvent instanceof CustomerAware) {
  58.             return;
  59.         }
  60.         $this->update($baseEvent->getContext(), $event->getConfig(), $baseEvent->getCustomerId());
  61.     }
  62.     public function handleFlow(StorableFlow $flow): void
  63.     {
  64.         if (!$flow->hasStore(CustomerAware::CUSTOMER_ID)) {
  65.             return;
  66.         }
  67.         $this->update($flow->getContext(), $flow->getConfig(), $flow->getStore(CustomerAware::CUSTOMER_ID));
  68.     }
  69.     /**
  70.      * @param array<string, mixed> $config
  71.      */
  72.     private function update(Context $context, array $configstring $customerId): void
  73.     {
  74.         if (!\array_key_exists('customerGroupId'$config)) {
  75.             return;
  76.         }
  77.         $customerGroupId $config['customerGroupId'];
  78.         if (empty($customerGroupId)) {
  79.             return;
  80.         }
  81.         $this->customerRepository->update([
  82.             [
  83.                 'id' => $customerId,
  84.                 'groupId' => $customerGroupId,
  85.             ],
  86.         ], $context);
  87.     }
  88. }