vendor/shopware/core/Content/Flow/Dispatching/Action/RemoveCustomerTagAction.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 RemoveCustomerTagAction extends FlowAction
  8. {
  9.     private EntityRepositoryInterface $customerTagRepository;
  10.     /**
  11.      * @internal
  12.      */
  13.     public function __construct(EntityRepositoryInterface $customerTagRepository)
  14.     {
  15.         $this->customerTagRepository $customerTagRepository;
  16.     }
  17.     public static function getName(): string
  18.     {
  19.         return 'action.remove.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) use ($baseEvent) {
  43.             return [
  44.                 'customerId' => $baseEvent->getCustomerId(),
  45.                 'tagId' => $tagId,
  46.             ];
  47.         }, $tagIds);
  48.         $this->customerTagRepository->delete($tags$baseEvent->getContext());
  49.     }
  50. }