-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnnwebSmartsuppLiveChat.php
84 lines (66 loc) · 3.15 KB
/
nnwebSmartsuppLiveChat.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
<?php
namespace nnwebSmartsuppLiveChat;
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\Models\Shop\Shop;
class nnwebSmartsuppLiveChat extends \Shopware\Components\Plugin {
public static function getSubscribedEvents() {
return [
'Enlight_Controller_Action_PostDispatchSecure_Frontend' => 'onFrontendPostDispatch'
];
}
public function activate(ActivateContext $context) {
$context->scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT);
parent::activate($context);
}
public function deactivate(DeactivateContext $context) {
$context->scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT);
parent::deactivate($context);
}
public function update(UpdateContext $context) {
$context->scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT);
parent::update($context);
}
public function onFrontendPostDispatch(\Enlight_Controller_ActionEventArgs $args) {
$shop = false;
if ($this->container->initialized('shop')) {
$shop = $this->container->get('shop');
}
if (!$shop) {
$shop = $this->container->get('models')->getRepository(Shop::class)->getActiveDefault();
}
$config = $this->container->get('shopware.plugin.cached_config_reader')->getByPluginName($this->getName(), $shop);
if (!(bool) $config['nnwebSmartsuppLiveChat_active']) {
return;
}
$controller = $args->get('subject');
$view = $controller->View();
$view->assign('smartsuppKey', $config["nnwebSmartsuppLiveChat_key"]);
$view->assign('smartsuppHideMobileWidget', $config["nnwebSmartsuppLiveChat_hideMobileWidget"]);
$view->assign('smartsuppChatBoxPosition', $config["nnwebSmartsuppLiveChat_chatBoxPosition"]);
$view->assign('smartsuppOffsetX', $config["nnwebSmartsuppLiveChat_offsetX"]);
$view->assign('smartsuppOffsetY', $config["nnwebSmartsuppLiveChat_offsetY"]);
$this->container->get('template')->addTemplateDir($this->getPath() . '/Resources/views/');
// User Status
$userLoggedIn = Shopware()->Modules()->Admin()->sCheckUser();
if ($userLoggedIn) {
$userData = Shopware()->Modules()->Admin()->sGetUserData();
$view->assign('smartsuppUserId', $userData["additional"]["user"]["id"]);
$view->assign('smartsuppCustomerNumber', $userData["additional"]["user"]["customernumber"]);
$view->assign('smartsuppCustomerGroup', $userData["additional"]["user"]["customergroup"]);
$view->assign('smartsuppName', $userData["additional"]["user"]["firstname"] . " " . $userData["additional"]["user"]["lastname"]);
$view->assign('smartsuppEmail', $userData["additional"]["user"]["email"]);
} else {
$view->assign('smartsuppUserId', "-");
$view->assign('smartsuppCustomerNumber', "-");
$view->assign('smartsuppCustomerGroup', "Gast");
$view->assign('smartsuppName', "");
$view->assign('smartsuppEmail', "");
}
$amount = Shopware()->Modules()->Basket()->sGetAmount();
$amount = empty($amount) ? 0 : $amount["totalAmount"];
$view->assign('smartsuppBasketAmount', $amount);
}
}