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