vendor/crehler/default-product-data/src/Subscriber/ProductWriteSubscriber.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @copyright 2020 Crehler Sp. z o. o. <https://crehler.com>
  4.  *
  5.  * @author    Jakub MedyƄski <jme@crehler.com>
  6.  * @support   Crehler <support@crehler.com>
  7.  * @created   09 gru 2020
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Crehler\DefaultProductData\Subscriber;
  13. use Crehler\DefaultProductData\Message\WriteProductMessage;
  14. use Enqueue\MessengerAdapter\EnvelopeItem\TransportConfiguration;
  15. use Shopware\Core\Content\Product\ProductEvents;
  16. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. use Symfony\Component\Messenger\MessageBusInterface;
  19. class ProductWriteSubscriber implements EventSubscriberInterface
  20. {
  21.     private MessageBusInterface $messageBus;
  22.     public function __construct(MessageBusInterface $messageBus)
  23.     {
  24.         $this->messageBus $messageBus;
  25.     }
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             ProductEvents::PRODUCT_WRITTEN_EVENT => 'onProductWrite'
  30.         ];
  31.     }
  32.     public function onProductWrite(EntityWrittenEvent $event): void
  33.     {
  34.         $message = new WriteProductMessage();
  35.         $message->withContext($event->getContext())
  36.             ->setIds($event->getIds());
  37.         $this->messageBus->dispatch(
  38.             $message,
  39.             [new TransportConfiguration(['topic' => 'crehlerdefaultproductdata'])]
  40.         );
  41.     }
  42. }