<?php
declare(strict_types=1);
namespace CnhProductExporter\Core\Content\Flow\Dispatching;
use CnhProductExporter\Services\API\TransferService;
use Shopware\Core\Checkout\Order\Event\OrderStateMachineStateChangeEvent;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Framework\Event\FlowEvent;
use Shopware\Core\Framework\Event\OrderAware;
class ActionCnhStatus extends FlowAction
{
/**
* @var \CnhProductExporter\Services\API\TransferService
*/
private TransferService $transferService;
public function __construct(TransferService $transferService)
{
$this->transferService = $transferService;
}
public static function getName(): string
{
return 'action.cnh.order.send';
}
public function requirements(): array
{
return [OrderAware::class];
}
public function handle(FlowEvent $event): void
{
/** @var OrderStateMachineStateChangeEvent $orderStateChangeEvent */
$orderStateChangeEvent = $event->getFlowState()->event;
$order = $orderStateChangeEvent->getOrder();
switch ($orderStateChangeEvent->getName()) {
case 'state_enter.order_delivery.state.shipped':
$this->transferService->sendOrderShipped($order->getId());
break;
case 'state_enter.order.state.cancelled':
$this->transferService->sendOrderCancelled($order->getId());
break;
default:
dd(
sprintf(
'Logic for state transition with name %s not implemented yet.',
$orderStateChangeEvent->getName()
)
);
}
}
public static function getSubscribedEvents()
{
return [
self::getName() => 'handle',
];
}
}