Skip to content

Commit 132b653

Browse files
committed
fix in smartsupp variables
1 parent 3254748 commit 132b653

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

src/Smartsupp/ChatGenerator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ public function render($print_out = false)
362362
}
363363

364364
$params = array();
365+
$params2 = array();
365366

366367
// set cookie domain if not blank
367368
if ($this->cookie_domain) {
@@ -388,11 +389,11 @@ public function render($print_out = false)
388389
// set detailed visitor's info
389390
// basic info
390391
if ($this->email) {
391-
$params[] = "smartsupp('email', '" . self::javascriptEscape($this->email) . "');";
392+
$params2[] = "smartsupp('email', '" . self::javascriptEscape($this->email) . "');";
392393
}
393394

394395
if ($this->name) {
395-
$params[] = "smartsupp('name', '" . self::javascriptEscape($this->name) . "');";
396+
$params2[] = "smartsupp('name', '" . self::javascriptEscape($this->name) . "');";
396397
}
397398

398399

@@ -406,7 +407,7 @@ public function render($print_out = false)
406407
"'}";
407408
}
408409

409-
$params[] = "smartsupp('variables', {" .
410+
$params2[] = "smartsupp('variables', {" .
410411
implode(", ", $options) .
411412
"});";
412413
}
@@ -442,7 +443,8 @@ public function render($print_out = false)
442443
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
443444
c.type='text/javascript';c.charset='utf-8';c.async=true;
444445
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
445-
})(document);
446+
})(document);"
447+
. implode("\n", $params2) . "
446448
</script>";
447449

448450
$code = str_replace('%key%', self::javascriptEscape($this->key), $code);

tests/ChatGeneratorTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,6 @@ public function test_render_allParams()
256256
_smartsupp.offsetX = 20; // offset from left or right, default 10
257257
_smartsupp.offsetY = 120; // offset from top, default 100
258258
_smartsupp.widget = 'button'; // by default 'widget'
259-
smartsupp('email', 'johny\\x40depp\\x2ecom');
260-
smartsupp('name', 'Johny\\x20Depp');
261-
smartsupp('variables', {orderTotal: {label: 'Total\\x20orders', value: '150'}, lastOrder: {label: 'Last\\x20ordered', value: '2015\\x2d07\\x2d09'}});
262259
_smartsupp.gaKey = 'UA\\x2d123456';
263260
_smartsupp.gaOptions = {'cookieDomain': '\\x2efoo\\x2ebar'};
264261
_smartsupp.hideWidget = true;
@@ -267,7 +264,9 @@ public function test_render_allParams()
267264
s=d.getElementsByTagName('script')[0];c=d.createElement('script');
268265
c.type='text/javascript';c.charset='utf-8';c.async=true;
269266
c.src='//www.smartsuppchat.com/loader.js';s.parentNode.insertBefore(c,s);
270-
})(document);
267+
})(document);smartsupp('email', 'johny\\x40depp\\x2ecom');
268+
smartsupp('name', 'Johny\\x20Depp');
269+
smartsupp('variables', {orderTotal: {label: 'Total\\x20orders', value: '150'}, lastOrder: {label: 'Last\\x20ordered', value: '2015\\x2d07\\x2d09'}});
271270
</script>";
272271

273272
$ret = $this->chat->render();

0 commit comments

Comments
 (0)