custom/plugins/CioProductDownload/src/Subscriber/CreateThumbnailSubscriber.php line 26

Open in your IDE?
  1. <?php
  2. namespace CioProductDownload\Subscriber;
  3. use CioProductDownload\Service\ThumbnailService;
  4. use Shopware\Core\Content\Product\ProductEvents;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CreateThumbnailSubscriber implements EventSubscriberInterface
  8. {
  9.     private ThumbnailService $thumbnailService;
  10.     public function __construct(ThumbnailService $thumbnailService)
  11.     {
  12.         $this->thumbnailService $thumbnailService;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             ProductEvents::PRODUCT_WRITTEN_EVENT => 'onProductWritten'
  18.         ];
  19.     }
  20.     public function onProductWritten(EntityWrittenEvent $event)
  21.     {
  22.         if ($event->getEntityName() == 'product') {
  23.             if ($event->getIds()) {
  24.                 if (count($event->getPayloads())) {
  25.                     if (count($event->getPayloads()[0])) {
  26.                         foreach ($event->getIds() as $productId) {
  27.                             $this->thumbnailService->createThumbnail($productId$event->getContext());
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.         }
  33.     }
  34. }