<?php declare(strict_types=1);
namespace Nd\Srs\Core\Content\Flow\Dispatching\Action;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\Framework\Uuid\Uuid;
use Nd\Srs\Core\Framework\Event\OrderAware;
use Nd\Srs\Service\OrderCommunicator;
use Shopware\Core\Framework\Event\FlowEvent;
class SendOrderAction extends FlowAction
{
private OrderCommunicator $OrderCommunicator;
public function __construct(OrderCommunicator $OrderCommunicator)
{
// you would need this repository to create a tag
$this->OrderCommunicator = $OrderCommunicator;
}
public static function getName(): string
{
// your own action name
return 'action.send.order';
}
public static function getSubscribedEvents(): array
{
return [
self::getName() => 'handle',
];
}
public function requirements(): array
{
return [OrderAware::class];
}
public function handle(FlowEvent $event): void
{
// config is the config data when created a flow sequence
$config = $event->getConfig();
// mail('mick@nodots.nl', 'DEV: Action triggered', 'Send order');
try {
$result = $this->OrderCommunicator->createOrder($event->getEvent()->getOrder()->getId(), $event->getContext());
}catch(\Exception $e){
mail('mick@nodots.nl', 'DEV: Action error', 'Error:' . json_encode($e->getLine()) . json_encode($e->getMessage()));
}
// mail('mick@nodots.nl', 'DEV: Action completed', 'Send order' . json_encode($result));
}
}