diff --git a/EventListeners/ConfigListener.php b/EventListeners/ConfigListener.php new file mode 100644 index 0000000..6c6e8f1 --- /dev/null +++ b/EventListeners/ConfigListener.php @@ -0,0 +1,45 @@ + [ + '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(LocalPickup::getModuleId()) + ->find(); + + $moduleConfig = []; + $moduleConfig['module'] = LocalPickup::getModuleCode(); + $configsCompleted = true; + + if ($shippingZoneConfig->count() === 0) { + $configsCompleted = false; + } + + $moduleConfig['completed'] = $configsCompleted; + + $event->setArgument('local.pickup.module.config', $moduleConfig); + } +}