vendor/store.shopware.com/netinexteasycoupon/src/Subscriber/CouponSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace NetInventors\NetiNextEasyCoupon\Subscriber;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeletedEvent;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class CouponSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var EntityRepositoryInterface
  13.      */
  14.     private $productConditionRepository;
  15.     public function __construct(EntityRepositoryInterface $productConditionRepository)
  16.     {
  17.         $this->productConditionRepository $productConditionRepository;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             'neti_easy_coupon_product.deleted' => 'onCouponProductDeleted',
  23.         ];
  24.     }
  25.     public function onCouponProductDeleted(EntityDeletedEvent $event): void
  26.     {
  27.         $ids      $event->getIds();
  28.         $context  $event->getContext();
  29.         $criteria = (new Criteria())->addFilter(new EqualsAnyFilter('couponId'$ids));
  30.         $ids      $this->productConditionRepository->search($criteria$context)->getIds();
  31.         $ids array_map(
  32.             static function ($id) {
  33.                 return [
  34.                     'id' => $id,
  35.                 ];
  36.             },
  37.             $ids
  38.         );
  39.         $this->productConditionRepository->delete(array_values($ids), $context);
  40.     }
  41. }