I've added a FlowAction that works fine, except for storing data within the StorableFlow. I'd really like to understand how to hydrate it properly.
Here is my current FlowAction:
class SameDayMailAction extends FlowAction
{
...
public function requirements(): array
{
return [OrderAware::class];
}
...
public function handleFlow(StorableFlow $flow): void
{
if (!$flow->hasStore(OrderAware::ORDER)) {
$this->logger->error(json_encode($flow->getStore(OrderAware::ORDER)));
return;
}
$order = $flow->getStore(OrderAware::ORDER);
$orderId = $flow->getStore(OrderAware::ORDER_ID);
$this->logger->debug('orderid' . $orderId);
$currentDate = (new DateTime())->format('Y-m-d');
$orderDate = $order->getOrderDate()->format('Y-m-d');
if ($currentDate !== $orderDate) {
return;
}
$this->samedayRepository->create([[
'id' => Uuid::randomHex(),
'orderId' => $orderId,
'clicked' => false
]], $flow->getContext());
}
}
The flow is being triggered correctly, but in the logs, I see app.ERROR: null [] []
.
Any advice on how to properly hydrate the StorableFlow would be greatly appreciated! Thanks in advance.
OrderAware
only transmit the orderId not the entire order entity. If you need the data of the order you must load the entity via the repository.
public function __construct(
private readonly EntityRepository $orderRepository
...
)
{
}
...
public function handleFlow(StorableFlow $flow): void
{
if (!$flow->hasData(OrderAware::ORDER_ID)) {
return;
}
$criteria = new Criteria([$flow->getData(OrderAware::ORDER_ID)]);
$order = $this->orderRepository->search($criteria, $flow->getContext())->first();
if (!$order) return;
...
}