forked from tawk/tawk-magento-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.php
More file actions
executable file
·149 lines (130 loc) · 4.13 KB
/
Index.php
File metadata and controls
executable file
·149 lines (130 loc) · 4.13 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
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
<?php
/**
* Tawk.to
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to support@tawk.to so we can send you a copy immediately.
*
* @copyright Copyright (c) 2024 Tawk.to
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Tawk\Widget\Controller\Adminhtml\StoreWidget;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\Result\JsonFactory;
use Psr\Log\LoggerInterface;
use Tawk\Widget\Model\WidgetFactory;
use Tawk\Widget\Helper\StringUtil;
use Tawk\Widget\Api\ConfigInterface;
class Index extends \Magento\Backend\App\Action
{
/**
* Json Factory instance
*
* @var JsonFactory $resultJsonfactory
*/
protected $resultJsonFactory;
/**
* Logger instance
*
* @var LoggerInterface $logger
*/
protected $logger;
/**
* Tawk.to Widget Model instance
*
* @var WidgetFactory $modelWidgetFactory
*/
protected $modelWidgetFactory;
/**
* Request body
*
* @var \Magento\Framework\App\RequestInterface $request
*/
protected $request;
/**
* String util helper
*
* @var StringUtil $helper
*/
protected $helper;
/**
* Constructor
*
* @param WidgetFactory $modelWidgetFactory Tawk.to Widget Model instance
* @param Context $context App Context
* @param JsonFactory $resultJsonFactory Json Factory instance
* @param LoggerInterface $logger PSR Logger
* @param StringUtil $helper String util helper
*/
public function __construct(
WidgetFactory $modelWidgetFactory,
Context $context,
JsonFactory $resultJsonFactory,
LoggerInterface $logger,
StringUtil $helper
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->logger = $logger;
$this->modelWidgetFactory = $modelWidgetFactory->create();
$this->request = $this->getRequest();
$this->helper = $helper;
}
/**
* Retrieves the store property, widget, and its visibility options.
*
* @return array {
* success: bool,
* pageid: string,
* widgetid: string,
* alwaysdisplay: int,
* excludeurl: string,
* donotdisplay: int,
* includeurl: string,
* enableVisitorRecognition: int,
* jsApiKey: string
* }
*/
public function execute()
{
$response = $this->resultJsonFactory->create();
$response->setHeader('Content-type', 'application/json');
$storeId = $this->helper->stripTagsandQuotes($this->request->getParam('id'));
if (!$storeId) {
return $response->setData(['success' => false]);
}
$model = $this->modelWidgetFactory->loadByForStoreId($storeId);
if (!$model->hasId()) {
$model = $this->modelWidgetFactory;
}
$pageId = $model->getPageId();
$widgetId = $model->getWidgetId();
$alwaysdisplay = $model->getAlwaysDisplay();
$excludeurl = $model->getExcludeUrl();
$donotdisplay = $model->getDoNotDisplay();
$includeurl = $model->getIncludeUrl();
$enableVisitorRecognition = $model->getEnableVisitorRecognition();
$jsApiKey = $model->getJsApiKey();
if (!empty($jsApiKey)) {
$jsApiKey = ConfigInterface::JS_API_KEY_NO_CHANGE;
}
return $response->setData([
'success' => true,
'pageid' => $pageId,
'widgetid' => $widgetId,
'alwaysdisplay' => $alwaysdisplay,
'excludeurl' => $excludeurl,
'donotdisplay' => $donotdisplay,
'includeurl' => $includeurl,
'enableVisitorRecognition' => $enableVisitorRecognition,
'jsApiKey' => $jsApiKey
]);
}
}