src/EventSubscriber/Order/AddPhotosToTransferQueueSubscriber.php line 30

  1. <?php
  2. /*
  3.  * This file is part of the Pellipop project.
  4.  *
  5.  * (c) Mobizel
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App\EventSubscriber\Order;
  12. use App\Entity\Order\Order;
  13. use App\Message\OrderItemPhotoMessage;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Symfony\Component\Messenger\MessageBusInterface;
  16. use Symfony\Component\Workflow\Event\Event;
  17. use Webmozart\Assert\Assert;
  18. class AddPhotosToTransferQueueSubscriber implements EventSubscriberInterface
  19. {
  20.     public function __construct(
  21.         private MessageBusInterface $messageBus,
  22.     ) {
  23.     }
  24.     public function onEnter(Event $event)
  25.     {
  26.         /** @var Order $order */
  27.         $order $event->getSubject();
  28.         Assert::isInstanceOf($orderOrder::class);
  29.         foreach ($order->getOrderItems() as $orderItem) {
  30.             foreach ($orderItem->getPhotos() as $orderItemPhoto) {
  31.                 $this->messageBus->dispatch(new OrderItemPhotoMessage($orderItemPhoto->getId()));
  32.             }
  33.         }
  34.     }
  35.     public static function getSubscribedEvents()
  36.     {
  37.         return [
  38.             'workflow.order_production.enter.uploaded' => ['onEnter'10],
  39.         ];
  40.     }
  41. }