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