vendor/kobizo/ecommerce-bundle/src/EventSubscriber/OrderWorkflowSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Kobizo\Bundle\ECommerceBundle\EventSubscriber;
  4. use DateTime;
  5. use Kobizo\Bundle\ECommerceBundle\Entity\Order;
  6. use Kobizo\Bundle\ECommerceBundle\Processor\Order\OrderHistoryProcessor;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\Workflow\Event\Event;
  9. class OrderWorkflowSubscriber implements EventSubscriberInterface
  10. {
  11.     private OrderHistoryProcessor $orderHistoryProcessor;
  12.     public function __construct(OrderHistoryProcessor $orderHistoryProcessor)
  13.     {
  14.         $this->orderHistoryProcessor $orderHistoryProcessor;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             'workflow.order.enter' => 'onEnter',
  20.         ];
  21.     }
  22.     public function onEnter(Event $event)
  23.     {
  24.         /** @var Order $order */
  25.         $order $event->getSubject();
  26.         $this->orderHistoryProcessor->add($ordersprintf(
  27.             '%s - Order #%s (ID=%s) performed transition "%s" from "%s" to "%s"',
  28.             (new DateTime())->format('Y-m-d H:i:s'),
  29.             $order->getReference(),
  30.             $order->getId(),
  31.             $event->getTransition()->getName(),
  32.             implode(', 'array_keys($order->getState())),
  33.             implode(', '$event->getTransition()->getTos())
  34.         ));
  35.     }
  36. }