-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWSCTagManagerSW5.php
217 lines (183 loc) · 7.71 KB
/
WSCTagManagerSW5.php
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
namespace WSCTagManagerSW5;
use Enlight_Event_EventArgs;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Shopware\Bundle\CookieBundle\CookieCollection;
use Shopware\Bundle\CookieBundle\Structs\CookieGroupStruct;
use Shopware\Bundle\CookieBundle\Structs\CookieStruct;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\DeactivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
use Shopware\Components\Plugin\Context\UpdateContext;
use Shopware\Components\Plugin;
class WSCTagManagerSW5 extends Plugin
{
public function install(InstallContext $context) {
$context->scheduleClearCache(InstallContext::CACHE_LIST_FRONTEND);
}
public function update(UpdateContext $context) {
$context->scheduleClearCache(UpdateContext::CACHE_LIST_ALL);
}
public function activate(ActivateContext $context) {
$context->scheduleClearCache(ActivateContext::CACHE_LIST_ALL);
}
public function deactivate(DeactivateContext $context) {
$context->scheduleClearCache(DeactivateContext::CACHE_LIST_ALL);
}
public static function getSubscribedEvents(): array
{
return [
'Enlight_Controller_Action_PostDispatch_Frontend' => 'onFrontend',
'Enlight_Controller_Action_PostDispatchSecure_Frontend_Checkout' => 'onFrontendCheckout',
'CookieCollector_Collect_Cookies' => 'addComfortCookie',
'Shopware_Modules_Basket_AddVoucher_Inserted' => 'voucherInserted'
];
}
public function voucherInserted(\Enlight_Event_EventArgs $args)
{
$code = $args->get('voucher')["vouchercode"];
$_SESSION["afvouchercode"] = $code;
}
public function onFrontend(\Enlight_Event_EventArgs $args)
{
$controller = $args->getSubject();
$view = $controller->View();
$view->addTemplateDir($this->getPath() . '/Resources/views');
}
public function onFrontendCheckout(\Enlight_Event_EventArgs $args)
{
$controller = $args->getSubject();
$view = $controller->View();
// Get the order number from the view
$orderNumber = $view->getAssign('sOrderNumber');
// Load the order object from the database using the order number
$order = Shopware()->Models()->getRepository('Shopware\Models\Order\Order')->findOneBy(['number' => $orderNumber]);
// Check if the order exists
if ($order) {
$code = $_SESSION["afvouchercode"];
$view->assign("afvouchercode", $code);
// Get the discount items from the order
$discounts = $order->getDetails()->filter(function ($item) {
return $item->getMode() == 3; // discount items have a mode of 3
});
// Check if there is at least one discount item
if (count($discounts) > 0) {
// Get the first discount item
$discount = $discounts->first();
// Get the coupon code from the name of the discount item
$couponCode = $discount->getArticleName();
// Assign the coupon code to the view so it can be displayed on the checkout page
$view->assign('couponCode', $couponCode);
}
}
}
public function addComfortCookie(): CookieCollection
{
$collection = new CookieCollection();
if (Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Bing')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Bing',
'/^wsc_Cookie_Bing$/',
'Bing (Microsoft Corporation Advertising)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Clarity')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Clarity',
'/^wsc_Cookie_Clarity$/',
'Clarity (Microsoft Corporation Clarity)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Facebook')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Facebook',
'/^wsc_Cookie_Facebook$/',
'Facebook (Meta Platforms Ireland Limited)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Google')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Google',
'/^wsc_Cookie_Google$/',
'Analytics / Tag-Manager (Google Ireland Limited)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_GoogleADs')) {
$collection->add(new CookieStruct(
'wsc_Cookie_GoogleADs',
'/^wsc_Cookie_GoogleADs$/',
'AdWords (Google Ireland Limited)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Hotjar')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Hotjar',
'/^wsc_Cookie_Hotjar$/',
'Hotjar Limited',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Instagram')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Instagram',
'/^wsc_Cookie_Instagram$/',
'Instagram (Meta Platforms Ireland Limited)',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_OpenWebAnalytics')) {
$collection->add(new CookieStruct(
'wsc_Cookie_OpenWebAnalytics',
'/^wsc_Cookie_OpenWebAnalytics$/',
'OpenWebAnalytics',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Matomo')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Matomo',
'/^wsc_Cookie_Matomo$/',
'Matomo',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Mautic')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Mautic',
'/^wsc_Cookie_Mautic$/',
'Mautic',
CookieGroupStruct::COMFORT
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Pinterest')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Pinterest',
'/^wsc_Cookie_Pinterest$/',
'Pinterest Inc.',
CookieGroupStruct::STATISTICS
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Youtube')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Youtube',
'/^wsc_Cookie_Youtube$/',
'Youtube (Google Ireland Limited)',
CookieGroupStruct::COMFORT
));
}
if(Shopware()->Config()->getByNamespace('WSCTagManagerSW5', 'wsc_Cookie_Zammad')) {
$collection->add(new CookieStruct(
'wsc_Cookie_Zammad',
'/^wsc_Cookie_Zammad$/',
'Zammad',
CookieGroupStruct::COMFORT
));
}
return $collection;
}
}