This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootstrap.php
More file actions
101 lines (94 loc) · 4.03 KB
/
Bootstrap.php
File metadata and controls
101 lines (94 loc) · 4.03 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php declare(strict_types=1);
/**
* @package Plugin\dh_bonuspunkte
* @author Dennis Heinrich
*/
namespace Plugin\dh_bonuspunkte;
use Exception;
use JTL\Events\Dispatcher;
use JTL\Plugin\Bootstrapper;
use Plugin\dh_bonuspunkte\source\classes\frontend\PageController;
use Plugin\dh_bonuspunkte\source\classes\frontend\script\ScriptManager;
use Plugin\dh_bonuspunkte\source\classes\frontend\script\ScriptType;
use Plugin\dh_bonuspunkte\source\classes\points\CartAbstractPoints;
use Plugin\dh_bonuspunkte\source\classes\points\LoginAbstractPoints;
use Plugin\dh_bonuspunkte\source\classes\points\RegisterAbstractPoints;
use Plugin\dh_bonuspunkte\source\classes\points\VisitAbstractPoints;
use Plugin\dh_bonuspunkte\source\classes\rewards\products\ProductRewards;
/**
* Class Bootstrap
* @package Plugin\dh_bonuspunkte
*/
class Bootstrap extends Bootstrapper
{
private Dispatcher $dispatcher;
private ScriptManager $scriptManager;
/**
* @inheritDoc
*/
public function boot(Dispatcher $dispatcher): void
{
global $pluginInterfaceForDhBonuspoints;
$pluginInterfaceForDhBonuspoints = $this->getPlugin();
$this->scriptManager = new ScriptManager();
$this->dispatcher = $dispatcher;
$this->dispatcherListeners();
}
/**
* The script manager is used to simplify the injection of certain
* scripts and snippets. Just use it via the `loadScript` method.
* @return ScriptManager
*/
public function getScriptManager(): ScriptManager
{
return $this->scriptManager;
}
/**
* Register the event listeners for the plugin,
* so that the plugin can react to the events of the shop
*/
private function dispatcherListeners(): void
{
// Hook: Update data in articles after loaded
$this->dispatcher->listen('shop.hook.'.HOOK_ARTIKEL_CLASS_FUELLEARTIKEL, function ($args) {
(new ProductRewards())->updateProductAfterLoaded($args['oArtikel']);
});
// Hook: Page in the frontend is loaded
$this->dispatcher->listen('shop.hook.' . HOOK_SEITE_PAGE, function () {
new PageController();
});
// Hook: Order status change
$this->dispatcher->listen('shop.hook.' . HOOK_BESTELLUNGEN_XML_BESTELLSTATUS, function ($args) {
(new CartAbstractPoints($args))->setOrderStatusProcessed();
});
// Hook: Order status changed to canceled
$this->dispatcher->listen('shop.hook.' . HOOK_BESTELLUNGEN_XML_BEARBEITESTORNO, function ($args) {
(new CartAbstractPoints($args))->setOrderStatusCanceled();
});
// Hook: Cart finalization
$this->dispatcher->listen('shop.hook.' . HOOK_BESTELLABSCHLUSS_INC_BESTELLUNGINDB_ENDE, function ($args) {
(new CartAbstractPoints($args))->executeRewardLogic();
});
// Hook: Account Login
$this->dispatcher->listen('shop.hook.' . HOOK_KUNDE_CLASS_HOLLOGINKUNDE, function ($args) {
(new LoginAbstractPoints($args))->executeRewardLogic();
});
// Hook: Registration
$this->dispatcher->listen('shop.hook.' . HOOK_REGISTRATION_CUSTOMER_CREATED, function ($args) {
(new RegisterAbstractPoints($args))->executeRewardLogic();
});
// Hook: Each visit, before the smarty template is rendered
$this->dispatcher->listen('shop.hook.' . HOOK_SMARTY_OUTPUTFILTER, function ($args) {
try {
(new ProductRewards())->reloadPageAfterCartChange();
(new VisitAbstractPoints($args))->executeRewardLogic();
$this->getScriptManager()->loadScript(ScriptType::DebugMessages);
$this->getScriptManager()->loadScript(ScriptType::WebpackInline);
} catch (Exception) {
// If an exception is thrown, the page will be served without the bonus points
// Just in case something goes wrong, the user should still be able to use the shop
}
});
(new ProductRewards())->updateCartPositionsForRewardProducts();
}
}