From bdae05e65f0672d0b1e76cf060b64de0b5c8579e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Laissus?= Date: Thu, 18 Apr 2024 17:59:00 +0200 Subject: [PATCH] feat: add configListener and update config.xml for Health Check --- Config/config.xml | 4 +++ EventListeners/ConfigListener.php | 55 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 EventListeners/ConfigListener.php diff --git a/Config/config.xml b/Config/config.xml index 64b71cb..418b39d 100644 --- a/Config/config.xml +++ b/Config/config.xml @@ -25,6 +25,10 @@ + + + + diff --git a/EventListeners/ConfigListener.php b/EventListeners/ConfigListener.php new file mode 100644 index 0000000..19b43b0 --- /dev/null +++ b/EventListeners/ConfigListener.php @@ -0,0 +1,55 @@ + [ + 'onModuleConfig', 128 + ], + ]; + } + + public function onModuleConfig(GenericEvent $event): void + { + $subject = $event->getSubject(); + + if ($subject !== "HealthStatus") { + throw new \RuntimeException('Event subject does not match expected value'); + } + + $shippingZoneConfig = AreaDeliveryModuleQuery::create() + ->filterByDeliveryModuleId(CustomDelivery::getModuleId()) + ->find(); + + $configModule = CustomDeliverySliceQuery::create() + ->find(); + + $moduleConfig = []; + $moduleConfig['module'] = CustomDelivery::getModuleCode(); + $configsCompleted = true; + + if ($configModule->count() === 0) { + $configsCompleted = false; + } + + if ($shippingZoneConfig->count() === 0) { + $configsCompleted = false; + } + + $moduleConfig['completed'] = $configsCompleted; + + $event->setArgument('delivery.module.config', $moduleConfig); + } +} \ No newline at end of file