vendor/shopware/core/Content/Flow/Dispatching/Action/AddCustomerTagAction.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 AddCustomerTagAction 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.add.customer.tag';
  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('tagIds'$config)) {
  35.             return;
  36.         }
  37.         $tagIds array_keys($config['tagIds']);
  38.         $baseEvent $event->getEvent();
  39.         if (!$baseEvent instanceof CustomerAware || empty($tagIds)) {
  40.             return;
  41.         }
  42.         $tags array_map(static function ($tagId) {
  43.             return ['id' => $tagId];
  44.         }, $tagIds);
  45.         $this->customerRepository->update([
  46.             [
  47.                 'id' => $baseEvent->getCustomerId(),
  48.                 'tags' => $tags,
  49.             ],
  50.         ], $baseEvent->getContext());
  51.     }
  52. }