forked from thielpeter/flexshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.php
91 lines (67 loc) · 2.8 KB
/
boot.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
<?php
/**
* @var rex_addon $this
*/
$addon = rex_addon::get('flexshop');
if (rex::isFrontend()) {
rex_extension::register('OUTPUT_FILTER', static function (rex_extension_point $ep) use ($addon) {
$ep->setSubject(str_ireplace(
['</head>'],
['<link rel="stylesheet" href="'. $addon->getAssetsUrl('flexshop.css') .'"></head>'],
$ep->getSubject())
);
});
rex_extension::register('OUTPUT_FILTER', static function (rex_extension_point $ep) use ($addon) {
$ep->setSubject(str_ireplace(
['</body>'],
[rex_flexshop_modals::getModal('addsuccess').'<script src="'. $addon->getAssetsUrl('flexshop.js') .'"></script></body>'],
$ep->getSubject())
);
});
}
rex_yform_manager_dataset::setModelClass('rex_flexshop_object', rex_flexshop_object::class);
rex_yform_manager_dataset::setModelClass('rex_flexshop_category', rex_flexshop_category::class);
rex_yform_manager_dataset::setModelClass('rex_flexshop_country', rex_flexshop_country::class);
if (!rex::isBackend()) {
rex_extension::register('OUTPUT_FILTER', function(rex_extension_point $ep) {
$content = $ep->getSubject();
$rex_flexshop = new rex_flexshop();
if (!is_null(rex_article::getCurrent())) {
preg_match_all("/REX_FLEXSHOP\[category=(.*?)]/", $content, $matches, PREG_SET_ORDER);
foreach($matches as $match){
$content = str_replace($match[0], rex_flexshop::getCategory($match[1]), $content);
}
preg_match_all("/REX_FLEXSHOP\[object=(.*?)]/", $content, $matches, PREG_SET_ORDER);
foreach($matches as $match){
$content = str_replace($match[0], rex_flexshop::get($match[1]), $content);
}
preg_match_all("/REX_FLEXSHOP\[cart]/", $content, $matches, PREG_SET_ORDER);
foreach($matches as $match){
$content = str_replace($match[0], $rex_flexshop->getCartOutput(), $content);
}
preg_match_all("/REX_FLEXSHOP\[cart=light]/", $content, $matches, PREG_SET_ORDER);
foreach($matches as $match){
$content = str_replace($match[0], rex_flexshop::getCartLight(), $content);
}
}
$ep->setSubject($content);
});
}
if (rex::isBackend())
{
rex_extension::register("YFORM_DATA_UPDATED", function( $ep ) {
if ($ep->getParam("table")->getTableName()=="rex_flexshop_order"){
$list = $ep->getSubject();
$oldData = $ep->getParam('old_data');
$newData = $list->objparams['value_pool']['sql'];
if($oldData['state'] !== "sent" && $newData['state'] === "sent"){
$template_name = 'flexshop_user_order_sent';
$etpl = rex_yform_email_template::getTemplate($template_name);
$etpl = rex_yform_email_template::replaceVars($etpl, $newData);
$etpl['mail_to'] = $newData['email'];
$etpl['mail_to_name'] = $newData['firstname'].' '.$newData['lastname'];
rex_yform_email_template::sendMail($etpl, $template_name);
}
}
});
}