custom/plugins/CkoShopware6/src/Subscriber/CheckoutOrderPlacedEventSubscriber.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Cko\Shopware6\Subscriber;
  3. use Cko\Shopware6\Service\Order\AbstractOrderService;
  4. use Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class CheckoutOrderPlacedEventSubscriber implements EventSubscriberInterface
  7. {
  8.     private AbstractOrderService $orderService;
  9.     public function __construct(AbstractOrderService $orderService)
  10.     {
  11.         $this->orderService $orderService;
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             CheckoutOrderPlacedEvent::class => 'onCheckoutOrderPlaced',
  17.         ];
  18.     }
  19.     /**
  20.      * Save the last order ID to the Order Service Instance to read it from the response subscriber
  21.      * This CheckoutOrderPlacedEvent event is triggered after the order is placed
  22.      *
  23.      * @see \Cko\Shopware6\Subscriber\BeforeSendResponseEventSubscriber::onBeforeSendResponse
  24.      */
  25.     public function onCheckoutOrderPlaced(CheckoutOrderPlacedEvent $event): void
  26.     {
  27.         $this->orderService->setRequestLastOrderId($event->getOrder()->getId());
  28.     }
  29. }