Skip to content

Commit 7a99b8f

Browse files
Merge pull request #27 from alvinjohnsonso/fix/saved-array-to-string-arrays
- changed default value of show_oncustom and hide_oncustom to string value of [] - added upgrade script to convert all arrays to string arrays in the visibility options setting
2 parents f369d2b + 043fe9b commit 7a99b8f

File tree

6 files changed

+207
-5
lines changed

6 files changed

+207
-5
lines changed

prestashop1.6/controllers/admin/AdminTawktoController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ public function ajaxProcessSetVisibility()
173173
'show_onfrontpage' => false,
174174
'show_oncategory' => false,
175175
'show_onproduct' => false,
176-
'show_oncustom' => array(),
176+
177+
// default value needs to be a json encoded of an empty array
178+
// since we're going to save a json encoded array later on.
179+
'show_oncustom' => json_encode(array()),
180+
177181
'enable_visitor_recognition' => false
178182
);
179183

prestashop1.6/tawkto.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ public function getPropertyAndWidget()
200200
);
201201
}
202202

203-
private function getArrayFromJson($data) {
203+
private function getArrayFromJson($data)
204+
{
204205
$arr = array();
205206
if (is_string($data)) {
206207
$data = json_decode($data);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* tawk.to
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Open Software License (OSL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @author tawkto [email protected]
16+
* @copyright Copyright (c) 2014-2021 tawk.to
17+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18+
*/
19+
20+
if (!defined('_PS_VERSION_')) {
21+
exit;
22+
}
23+
24+
function upgrade_module_1_2_3()
25+
{
26+
// update the records for TAWKTO_WIDGET_OPTS.
27+
$update_records_result = update_records();
28+
if (!$update_records_result) {
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
35+
function update_records()
36+
{
37+
$res = true;
38+
39+
// modify global first
40+
$res &= update_visibility_opts();
41+
42+
$shop_ids = Shop::getCompleteListOfShopsID();
43+
44+
$updated_groups = array();
45+
foreach ($shop_ids as $shop_id) {
46+
$shop_group_id = (int)Shop::getGroupFromShop($shop_id);
47+
48+
if (!in_array($shop_group_id, $updated_groups)) {
49+
// update the group config
50+
$res &= update_visibility_opts($shop_group_id);
51+
$updated_groups[] = $shop_group_id;
52+
}
53+
54+
// update the shop config
55+
$res &= update_visibility_opts($shop_group_id, $shop_id);
56+
}
57+
58+
return $res;
59+
}
60+
61+
function update_visibility_opts($shop_group_id = null, $shop_id = null)
62+
{
63+
if (isset($shop_id)) {
64+
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
65+
} elseif (isset($shop_group_id)) {
66+
Shop::setContext(Shop::CONTEXT_GROUP, $shop_group_id);
67+
} else {
68+
Shop::setContext(Shop::CONTEXT_ALL);
69+
}
70+
71+
$opts = Configuration::get(TawkTo::TAWKTO_WIDGET_OPTS, null, $shop_group_id, $shop_id);
72+
73+
if (!$opts) {
74+
return false;
75+
}
76+
77+
$opts = json_decode($opts);
78+
79+
if (isset($opts->show_oncustom) && is_array($opts->show_oncustom) && $opts->show_oncustom === array()) {
80+
$opts->show_oncustom = json_encode(array());
81+
}
82+
83+
if (isset($opts->hide_oncustom) && is_array($opts->hide_oncustom) && $opts->hide_oncustom === array()) {
84+
$opts->hide_oncustom = json_encode(array());
85+
}
86+
87+
return Configuration::updateValue(
88+
TawkTo::TAWKTO_WIDGET_OPTS,
89+
json_encode($opts),
90+
false,
91+
$shop_group_id,
92+
$shop_id
93+
);
94+
}

prestashop1.7/controllers/admin/AdminTawktoController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,19 @@ public function ajaxProcessSetVisibility()
171171
{
172172
$jsonOpts = array(
173173
'always_display' => false,
174-
'hide_oncustom' => array(),
174+
175+
// default value needs to be a json encoded of an empty array
176+
// since we're going to save a json encoded array later on.
177+
'hide_oncustom' => json_encode(array()),
178+
175179
'show_onfrontpage' => false,
176180
'show_oncategory' => false,
177181
'show_onproduct' => false,
178-
'show_oncustom' => array(),
182+
183+
// default value needs to be a json encoded of an empty array
184+
// since we're going to save a json encoded array later on.
185+
'show_oncustom' => json_encode(array()),
186+
179187
'enable_visitor_recognition' => false
180188
);
181189

prestashop1.7/tawkto.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ public function getPropertyAndWidget()
228228
);
229229
}
230230

231-
private function getArrayFromJson($data) {
231+
private function getArrayFromJson($data)
232+
{
232233
$arr = array();
233234
if (is_string($data)) {
234235
$data = json_decode($data);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* tawk.to
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Open Software License (OSL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/osl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @author tawkto [email protected]
16+
* @copyright Copyright (c) 2014-2021 tawk.to
17+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18+
*/
19+
20+
if (!defined('_PS_VERSION_')) {
21+
exit;
22+
}
23+
24+
function upgrade_module_1_2_3()
25+
{
26+
// update the records for TAWKTO_WIDGET_OPTS.
27+
$update_records_result = update_records();
28+
if (!$update_records_result) {
29+
return false;
30+
}
31+
32+
return true;
33+
}
34+
35+
function update_records()
36+
{
37+
$res = true;
38+
39+
// modify global first
40+
$res &= update_visibility_opts();
41+
42+
$shop_ids = Shop::getCompleteListOfShopsID();
43+
44+
$updated_groups = array();
45+
foreach ($shop_ids as $shop_id) {
46+
$shop_group_id = (int)Shop::getGroupFromShop($shop_id);
47+
48+
if (!in_array($shop_group_id, $updated_groups)) {
49+
// update the group config
50+
$res &= update_visibility_opts($shop_group_id);
51+
$updated_groups[] = $shop_group_id;
52+
}
53+
54+
// update the shop config
55+
$res &= update_visibility_opts($shop_group_id, $shop_id);
56+
}
57+
58+
return $res;
59+
}
60+
61+
function update_visibility_opts($shop_group_id = null, $shop_id = null)
62+
{
63+
if (isset($shop_id)) {
64+
Shop::setContext(Shop::CONTEXT_SHOP, $shop_id);
65+
} elseif (isset($shop_group_id)) {
66+
Shop::setContext(Shop::CONTEXT_GROUP, $shop_group_id);
67+
} else {
68+
Shop::setContext(Shop::CONTEXT_ALL);
69+
}
70+
71+
$opts = Configuration::get(TawkTo::TAWKTO_WIDGET_OPTS, null, $shop_group_id, $shop_id);
72+
73+
if (!$opts) {
74+
return false;
75+
}
76+
77+
$opts = json_decode($opts);
78+
79+
if (isset($opts->show_oncustom) && is_array($opts->show_oncustom) && $opts->show_oncustom === array()) {
80+
$opts->show_oncustom = json_encode(array());
81+
}
82+
83+
if (isset($opts->hide_oncustom) && is_array($opts->hide_oncustom) && $opts->hide_oncustom === array()) {
84+
$opts->hide_oncustom = json_encode(array());
85+
}
86+
87+
return Configuration::updateValue(
88+
TawkTo::TAWKTO_WIDGET_OPTS,
89+
json_encode($opts),
90+
false,
91+
$shop_group_id,
92+
$shop_id
93+
);
94+
}

0 commit comments

Comments
 (0)