1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
$Id$ |
4
|
|
|
|
5
|
|
|
osCommerce, Open Source E-Commerce Solutions |
6
|
|
|
http://www.oscommerce.com |
7
|
|
|
|
8
|
|
|
Copyright (c) 2010 osCommerce |
9
|
|
|
|
10
|
|
|
Released under the GNU General Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
define('TABLE_PAGANTIS_CONFIG', 'pagantis_config'); |
14
|
|
|
define('MODULE_HEADER_TAGS_PAGANTIS_SDK', 'https://cdn.pagantis.com/js/pg-v2/sdk.js'); |
15
|
|
|
|
16
|
|
|
class ht_pagantis { |
17
|
|
|
var $code = 'ht_pagantis'; |
18
|
|
|
var $group = 'header_tags'; |
19
|
|
|
var $title; |
20
|
|
|
var $description; |
21
|
|
|
var $enabled = false; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* ht_pagantis constructor. |
25
|
|
|
*/ |
26
|
|
|
function ht_pagantis() { |
|
|
|
|
27
|
|
|
$this->title = MODULE_HEADER_TAGS_PAGANTIS_TITLE; |
28
|
|
|
$this->description = MODULE_HEADER_TAGS_PAGANTIS_DESCRIPTION; |
29
|
|
|
$this->sort_order = 0; |
|
|
|
|
30
|
|
|
|
31
|
|
|
if ( defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS') ) { |
32
|
|
|
$this->enabled = (MODULE_HEADER_TAGS_PAGANTIS_STATUS == 'True'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$this->extraConfig = $this->getExtraConfig(); |
|
|
|
|
36
|
|
|
$this->pk = $this->getConfig('MODULE_PAYMENT_PAGANTIS_PK'); |
|
|
|
|
37
|
|
|
$this->sdkFile = MODULE_HEADER_TAGS_PAGANTIS_SDK; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
private function getExtraConfig() |
44
|
|
|
{ |
45
|
|
|
$checkTable = tep_db_query("SHOW TABLES LIKE '".TABLE_PAGANTIS_CONFIG."'"); |
|
|
|
|
46
|
|
|
$response = array(); |
47
|
|
|
if (tep_db_num_rows($checkTable) > 0) { |
|
|
|
|
48
|
|
|
$query = "select * from ".TABLE_PAGANTIS_CONFIG; |
49
|
|
|
$result = tep_db_query($query); |
50
|
|
|
$response = array(); |
51
|
|
|
while ($resultArray = tep_db_fetch_array($result)) { |
|
|
|
|
52
|
|
|
$response[$resultArray['config']] = $resultArray['value']; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
return $response; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $config |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
private function getConfig($config = '') |
63
|
|
|
{ |
64
|
|
|
$query = "select configuration_value from ".TABLE_CONFIGURATION . " where configuration_key = '" . $config . "'"; |
|
|
|
|
65
|
|
|
$result = tep_db_query($query); |
|
|
|
|
66
|
|
|
$resultArray = tep_db_fetch_array($result); |
|
|
|
|
67
|
|
|
return $resultArray['configuration_value']; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Execute function |
72
|
|
|
*/ |
73
|
|
|
function execute() { |
|
|
|
|
74
|
|
|
global $languages_id; |
75
|
|
|
if (isset($GLOBALS["HTTP_GET_VARS"]["products_id"])) { |
76
|
|
|
$simulatorCode = 'pgSDK'; |
77
|
|
|
if ($languages_id == '2' || $languages_id == null) { |
78
|
|
|
$this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] = 'pmtSDK.simulator.positions.INNER'; |
|
|
|
|
79
|
|
|
$this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] = 'pmtSDK.simulator.types.SIMPLE'; |
80
|
|
|
$this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] = 'pmtSDK.simulator.skins.BLUE'; |
81
|
|
|
$simulatorCode = 'pmtSDK'; |
82
|
|
|
} |
83
|
|
|
echo "<script src='".$this->sdkFile."'></script>". PHP_EOL; |
84
|
|
|
echo '<script>'. PHP_EOL; |
85
|
|
|
echo ' function loadSimulator()'. PHP_EOL; |
86
|
|
|
echo ' {'. PHP_EOL; |
87
|
|
|
echo ' if (typeof '.$simulatorCode.' != \'undefined\') {'. PHP_EOL; |
88
|
|
|
echo ' var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
89
|
|
|
echo ' var priceSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_PRICE_SELECTOR']. '\';'. PHP_EOL; |
90
|
|
|
echo ' var quantitySelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_QUANTITY_SELECTOR']. '\';'. PHP_EOL; |
91
|
|
|
|
92
|
|
|
echo ' if (positionSelector === \'default\') {'. PHP_EOL; |
93
|
|
|
echo ' positionSelector = \'.buttonSet\''. PHP_EOL; |
94
|
|
|
echo ' }'. PHP_EOL; |
95
|
|
|
|
96
|
|
|
echo ' if (priceSelector === \'default\') {'. PHP_EOL; |
97
|
|
|
echo ' priceSelector = \'#bodyContent>form>div>h1\''. PHP_EOL; |
98
|
|
|
echo ' }'. PHP_EOL; |
99
|
|
|
|
100
|
|
|
echo ' '.$simulatorCode.'.product_simulator = {};'. PHP_EOL; |
101
|
|
|
echo ' '.$simulatorCode.'.product_simulator.id = \'product-simulator\';'. PHP_EOL; |
102
|
|
|
echo ' '.$simulatorCode.'.product_simulator.publicKey = \'' . $this->pk . '\';'. PHP_EOL; |
|
|
|
|
103
|
|
|
echo ' '.$simulatorCode.'.product_simulator.selector = positionSelector;'. PHP_EOL; |
104
|
|
|
echo ' '.$simulatorCode.'.product_simulator.numInstalments = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] . '\';'. PHP_EOL; |
105
|
|
|
echo ' '.$simulatorCode.'.product_simulator.type = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_TYPE'] . ';'. PHP_EOL; |
106
|
|
|
echo ' '.$simulatorCode.'.product_simulator.skin = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_SKIN'] . ';'. PHP_EOL; |
107
|
|
|
echo ' '.$simulatorCode.'.product_simulator.position = ' . $this->extraConfig['PAGANTIS_SIMULATOR_DISPLAY_CSS_POSITION'] . ';'. PHP_EOL; |
108
|
|
|
echo ' '.$simulatorCode.'.product_simulator.itemAmountSelector = priceSelector;'. PHP_EOL; |
109
|
|
|
|
110
|
|
|
echo ' '.$simulatorCode.'.simulator.init('.$simulatorCode.'.product_simulator);'. PHP_EOL; |
111
|
|
|
echo ' clearInterval(window.PSSimulatorId);'. PHP_EOL; |
112
|
|
|
echo ' return true;'. PHP_EOL; |
113
|
|
|
echo ' }'. PHP_EOL; |
114
|
|
|
echo ' return false;'. PHP_EOL; |
115
|
|
|
echo ' }'. PHP_EOL; |
116
|
|
|
echo ' window.PSSimulatorId = setInterval(function () {'. PHP_EOL; |
117
|
|
|
echo ' loadSimulator();'. PHP_EOL; |
118
|
|
|
echo ' }, 2000);'. PHP_EOL; |
119
|
|
|
echo '</script>'. PHP_EOL; |
120
|
|
|
|
121
|
|
|
if ($this->isPromoted($GLOBALS["HTTP_GET_VARS"]["products_id"])) { |
122
|
|
|
echo "<div id='promotedText' style='display:none'><br/>".$this->extraConfig['PAGANTIS_PROMOTED_PRODUCT_CODE']."</div>"; |
123
|
|
|
echo '<script>'. PHP_EOL; |
124
|
|
|
echo ' function loadPromoted()'. PHP_EOL; |
125
|
|
|
echo ' {'. PHP_EOL; |
126
|
|
|
echo 'var positionSelector = \'' . $this->extraConfig['PAGANTIS_SIMULATOR_CSS_POSITION_SELECTOR']. '\';'. PHP_EOL; |
127
|
|
|
echo 'if (positionSelector === \'default\') {'. PHP_EOL; |
128
|
|
|
echo 'positionSelector = \'.buttonSet\''. PHP_EOL; |
129
|
|
|
echo '}'. PHP_EOL; |
130
|
|
|
echo 'var docFather = document.querySelector(positionSelector);'.PHP_EOL; |
131
|
|
|
echo 'if (typeof docFather != \'undefined\') {'. PHP_EOL; |
132
|
|
|
echo 'var promotedNode = document.getElementById("promotedText");'.PHP_EOL; |
133
|
|
|
echo 'docFather.appendChild(promotedNode);'.PHP_EOL; |
134
|
|
|
echo 'promotedNode.style.display=""' . PHP_EOL; |
135
|
|
|
echo ' return true;'. PHP_EOL; |
136
|
|
|
echo ' }'. PHP_EOL; |
137
|
|
|
echo ' return false;'. PHP_EOL; |
138
|
|
|
echo ' }'. PHP_EOL; |
139
|
|
|
echo ' window.PSPromotedId = setInterval(function () {'. PHP_EOL; |
140
|
|
|
echo ' loadPromoted();'. PHP_EOL; |
141
|
|
|
echo ' }, 2000);'. PHP_EOL; |
142
|
|
|
echo '</script>'. PHP_EOL; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @return bool |
149
|
|
|
*/ |
150
|
|
|
function isEnabled() { |
|
|
|
|
151
|
|
|
return $this->enabled; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return bool |
156
|
|
|
*/ |
157
|
|
|
function check() { |
|
|
|
|
158
|
|
|
return defined('MODULE_HEADER_TAGS_PAGANTIS_STATUS'); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* install |
163
|
|
|
*/ |
164
|
|
|
function install() { |
|
|
|
|
165
|
|
|
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable Pagantis Module', 'MODULE_HEADER_TAGS_PAGANTIS_STATUS', 'True', '', '6', '1', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())"); |
|
|
|
|
166
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* remove |
171
|
|
|
*/ |
172
|
|
|
function remove() { |
|
|
|
|
173
|
|
|
tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')"); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return array |
178
|
|
|
*/ |
179
|
|
|
function keys() { |
|
|
|
|
180
|
|
|
return array('MODULE_HEADER_TAGS_PAGANTIS_STATUS'); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @param $productId |
185
|
|
|
* |
186
|
|
|
* @return bool |
187
|
|
|
*/ |
188
|
|
|
private function isPromoted($productId) |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
//HOOK WHILE PROMOTED AMOUNT IS NOT WORKING |
191
|
|
|
return false; |
192
|
|
|
|
193
|
|
|
if ($this->extraConfig['PAGANTIS_PROMOTION'] == '') { |
|
|
|
|
194
|
|
|
$promotedProducts = array(); |
195
|
|
|
} else { |
196
|
|
|
$promotedProducts = array_values((array)unserialize($this->extraConfig['PAGANTIS_PROMOTION'])); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
return (in_array($productId, $promotedProducts)); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
?> |
|
|
|
|
203
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.