-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathConfigListener.php
More file actions
71 lines (54 loc) · 1.95 KB
/
ConfigListener.php
File metadata and controls
71 lines (54 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace PayPlugModule\EventListener;
use PayPlugModule\PayPlugModule;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Thelia\Model\ModuleConfigQuery;
class ConfigListener implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
'module.config' => [
'onModuleConfig', 128
],
];
}
public function onModuleConfig(GenericEvent $event): void
{
$subject = $event->getSubject();
if ($subject !== "HealthStatus") {
throw new \RuntimeException('Event subject does not match expected value');
}
$configModule = ModuleConfigQuery::create()
->filterByModuleId(PayPlugModule::getModuleId())
->filterByName(['live_api_key', 'test_api_key', 'payment_page_type', 'api_mode', 'payment_enabled'])
->find();
$moduleConfig = [];
$moduleConfig['module'] = PayPlugModule::getModuleCode();
$paymentEnabled = false;
$liveApiKey = null;
$testApiKey = null;
foreach ($configModule as $config) {
$name = $config->getName();
$value = $config->getValue();
if ($name === 'payment_enabled') {
$paymentEnabled = $value == 1;
}
if ($name === 'live_api_key') {
$liveApiKey = $value;
}
if ($name === 'test_api_key') {
$testApiKey = $value;
}
$moduleConfig[$name] = $value;
}
if (($liveApiKey !== null || $testApiKey !== null) && $paymentEnabled) {
$moduleConfig['completed'] = true;
} else {
$moduleConfig['completed'] = false;
}
$moduleConfig['payment_enabled'] = $paymentEnabled;
$event->setArgument('payplug.module.config', $moduleConfig);
}
}