custom/plugins/cnh-product-exporter-main/src/Core/Content/Flow/Dispatching/ActionCnhStatus.php line 38

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace CnhProductExporter\Core\Content\Flow\Dispatching;
  4. use CnhProductExporter\Services\API\TransferService;
  5. use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
  6. use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
  7. use Shopware\Core\Framework\Event\FlowEvent;
  8. use Shopware\Core\Framework\Event\OrderAware;
  9. class ActionCnhStatus extends FlowAction
  10. {
  11.     /**
  12.      * @var \CnhProductExporter\Services\API\TransferService
  13.      */
  14.     private TransferService $transferService;
  15.     public function __construct(TransferService $transferService)
  16.     {
  17.         $this->transferService $transferService;
  18.     }
  19.     public static function getName(): string
  20.     {
  21.         return 'action.cnh.order.send';
  22.     }
  23.     public function requirements(): array
  24.     {
  25.         return [OrderAware::class];
  26.     }
  27.     public function handle(FlowEvent $event): void
  28.     {
  29.         /** @var OrderStateMachineStateChangeEvent $orderStateChangeEvent */
  30.         $orderStateChangeEvent $event->getFlowState()->event;
  31.         $order $orderStateChangeEvent->getOrder();
  32.         switch ($orderStateChangeEvent->getName()) {
  33.             case 'state_enter.order_delivery.state.shipped':
  34.                 $this->transferService->sendOrderShipped($order->getId());
  35.                 break;
  36.             case 'state_enter.order.state.cancelled':
  37.                 $this->transferService->sendOrderCancelled($order->getId());
  38.                 break;
  39.             default:
  40.                 dd(
  41.                     sprintf(
  42.                         'Logic for state transition with name %s not implemented yet.',
  43.                         $orderStateChangeEvent->getName()
  44.                     )
  45.                 );
  46.         }
  47.     }
  48.     public static function getSubscribedEvents()
  49.     {
  50.         return [
  51.             self::getName() => 'handle',
  52.         ];
  53.     }
  54. }