From a618b0ff307ee5bd98c975ff6a157b1b4cc23d4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joachim=20L=C3=B8vgaard?= Date: Thu, 29 Aug 2024 13:12:28 +0200 Subject: [PATCH] Add order listener --- src/EventListener/Doctrine/OrderListener.php | 38 +++++++++++++++++++ .../config/services/event_listener.xml | 7 ++++ 2 files changed, 45 insertions(+) create mode 100644 src/EventListener/Doctrine/OrderListener.php diff --git a/src/EventListener/Doctrine/OrderListener.php b/src/EventListener/Doctrine/OrderListener.php new file mode 100644 index 0000000..ccc3a65 --- /dev/null +++ b/src/EventListener/Doctrine/OrderListener.php @@ -0,0 +1,38 @@ +getObject(); + if (!$obj instanceof OrderInterface) { + return; + } + + // For now this listener only triggers when the state changes + if (!$eventArgs->hasChangedField('state')) { + return; + } + + $uploadOrderRequest = $obj->getPeakUploadOrderRequest() ?? $this->uploadOrderRequestFactory->createNew(); + $this->uploadOrderRequestWorkflow->apply($uploadOrderRequest, UploadOrderRequestWorkflow::TRANSITION_RESET); + + $obj->setPeakUploadOrderRequest($uploadOrderRequest); + } +} diff --git a/src/Resources/config/services/event_listener.xml b/src/Resources/config/services/event_listener.xml index f0b6701..572f76f 100644 --- a/src/Resources/config/services/event_listener.xml +++ b/src/Resources/config/services/event_listener.xml @@ -2,6 +2,13 @@ + + + + + + +