vendor/store.shopware.com/ennodigitalproducts/Subscriber/EnnoDownloadSetProductRelationsWritten.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace EnnoDigitalProducts\Subscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use EnnoDigitalProducts\EnnoDownload\Aggregate\EnnoDownloadSetProductRelations\EnnoDownloadSetProductRelationsEvents;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  10. use Shopware\Core\Framework\Context;
  11. class EnnoDownloadSetProductRelationsWritten implements EventSubscriberInterface
  12. {
  13.     private $requestStack;
  14.     private $ennoDigitalProductSettingsRepository;
  15.     public function __construct(EntityRepositoryInterface $ennoDigitalProductSettingsRepository)
  16.     {
  17.         $this->ennoDigitalProductSettingsRepository $ennoDigitalProductSettingsRepository;
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             EnnoDownloadSetProductRelationsEvents::ENNO_DOWNLOAD_SET_PRODUCT_RELATIONS_WRITTEN_EVENT => 'onEnnoDownloadSetProductRelationWritten'
  23.         ];
  24.     }
  25.     public function onEnnoDownloadSetProductRelationWritten(EntityWrittenEvent $event)
  26.     {
  27.         $errors $event->getErrors();
  28.         if(is_array($errors) && !empty($errors)) return;
  29.         $transactions $event->getPayloads();
  30.         if(!(is_array($transactions) && !empty($transactions))) return;
  31.         $context Context::createDefaultContext();
  32.         foreach ($transactions as $transaction)
  33.         {
  34.             $this->ennoDigitalProductSettingsRepository->upsert(
  35.                 [
  36.                     ['productId' => $transaction['productId'], 'downloadsInheritanceId' => $transaction['productId']]
  37.                 ],
  38.                 $context
  39.             );
  40.         }
  41.     }
  42. }