custom/static-plugins/CioFormBuilder/src/Subscriber/OrderChangesSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace CioFormBuilder\Subscriber;
  3. use CioSponsoredOrderConfirmation\CioSponsoredOrderConfirmation;
  4. use CioFormBuilder\Service\OrderConfirmationService;
  5. use Shopware\Core\Checkout\Order\OrderStates;
  6. use Shopware\Core\System\StateMachine\Event\StateMachineTransitionEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class OrderChangesSubscriber implements EventSubscriberInterface
  9. {
  10.     private OrderConfirmationService $orderConfirmationService;
  11.     public function __construct(OrderConfirmationService $orderConfirmationService)
  12.     {
  13.         $this->orderConfirmationService $orderConfirmationService;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             StateMachineTransitionEvent::class => 'onStateMachineTransition',
  19.         ];
  20.     }
  21.     public function onStateMachineTransition(StateMachineTransitionEvent $event)
  22.     {
  23.         if ($event->getToPlace()->getTechnicalName() == CioSponsoredOrderConfirmation::SPONSORED_ORDER_RELEASED_STATE_TECHNICAL_NAME) {
  24.             $order $this->orderConfirmationService->getOrder($event->getEntityId(), $event->getContext());
  25.             $this->orderConfirmationService->allow($order$event->getContext());
  26.         }
  27.         if ($event->getToPlace()->getTechnicalName() == OrderStates::STATE_CANCELLED || $event->getToPlace()->getTechnicalName() == CioSponsoredOrderConfirmation::SPONSORED_ORDER_CANCEL_STATE_TECHNICAL_NAME) {
  28.             $order $this->orderConfirmationService->getOrder($event->getEntityId(), $event->getContext());
  29.             $this->orderConfirmationService->deny($order$event->getContext());
  30.         }
  31.     }
  32. }