How do I execute this script?
How do I execute this script?
We are using ce-phoenix_1.05 with php v7.2.5
The livechat is installed on the same server as the website. I need to execute this script below on our website to display this livechat window on the website frontend pages.
<script>var LHC_API = LHC_API||{};
LHC_API.args = {mode:'widget',lhc_base_url:'//mysite.com/livehelperchat/lhc_web/index.php/',wheight:450,wwidth:350,pheight:520,pwidth:500,leaveamessage:true,check_messages:false};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.setAttribute('crossorigin','anonymous'); po.async = true;
var date = new Date();po.src = '//mysite.com/livehelperchat/lhc_web/design/defaulttheme/js/widgetv2/index.js?'+(""+date.getFullYear() + date.getMonth() + date.getDate());
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
What do I need to do to get this script working? Thank you.
Regards,
Rich-OS
The livechat is installed on the same server as the website. I need to execute this script below on our website to display this livechat window on the website frontend pages.
<script>var LHC_API = LHC_API||{};
LHC_API.args = {mode:'widget',lhc_base_url:'//mysite.com/livehelperchat/lhc_web/index.php/',wheight:450,wwidth:350,pheight:520,pwidth:500,leaveamessage:true,check_messages:false};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.setAttribute('crossorigin','anonymous'); po.async = true;
var date = new Date();po.src = '//mysite.com/livehelperchat/lhc_web/design/defaulttheme/js/widgetv2/index.js?'+(""+date.getFullYear() + date.getMonth() + date.getDate());
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
What do I need to do to get this script working? Thank you.
Regards,
Rich-OS
Last edited by Rich-Os on Mon Nov 21, 2022 9:57 pm, edited 2 times in total.
-
- VIP Member
- Posts: 2025
- Joined: Mon Oct 07, 2019 4:39 am
- : Buy Me A Beverage
- Has thanked: 28 times
- Been thanked: 187 times
Re: How do I execute this script?
Maybe as a hook.
See core code for an example:
https://github.com/CE-PhoenixCart/Phoen ... jQuery.php
Re: How do I execute this script?
Thank you heatherbell.
I used the script as you suggested. I basically changed the script <> in the file for the new script I wanted to execute. Hook doesn't like it and browser threw an HTTP ERROR 500 in the admin.
The chat url (a sub of the main site) is working fine. The problem is just to integrate it with the Phoenix website.
Is this an impossible integration for Phoenix?
Or does that mean there is no specific way to integrate a script (external) with Phoenix?
Many thanks in advance.
I used the script as you suggested. I basically changed the script <> in the file for the new script I wanted to execute. Hook doesn't like it and browser threw an HTTP ERROR 500 in the admin.
The chat url (a sub of the main site) is working fine. The problem is just to integrate it with the Phoenix website.
Is this an impossible integration for Phoenix?
Or does that mean there is no specific way to integrate a script (external) with Phoenix?
Many thanks in advance.
-
- VIP Member
- Posts: 483
- Joined: Fri Oct 25, 2019 5:06 pm
- Has thanked: 48 times
- Been thanked: 28 times
Re: How do I execute this script?
@Rich-Os
here is the hook ,, test it on 1.0.8.19 and its working.. save it in includes/hooks/shop/siteWide/ change the links for you site and name it livehelperchat.php
here is the hook ,, test it on 1.0.8.19 and its working.. save it in includes/hooks/shop/siteWide/ change the links for you site and name it livehelperchat.php
Code: Select all
class hook_shop_siteWide_livehelperchat {
var $version = '3.4.1';
var $sitestart = null;
function listen_injectSiteStart() {
$this->sitestart .= '<!-- livehelperchat hooked -->' . PHP_EOL;
$this->sitestart .= '<script>var LHC_API = LHC_API||{};
LHC_API.args = {mode:"widget",lhc_base_url:"//mysite.com/livehelperchat/lhc_web/index.php/",wheight:450,wwidth:350,pheight:520,pwidth:500,leaveamessage:true,check_messages:false};
(function() {
var po = document.createElement("script"); po.type = "text/javascript"; po.setAttribute("crossorigin","anonymous"); po.async = true;
var date = new Date();po.src = "//mysite.com/livehelperchat/lhc_web/design/defaulttheme/js/widgetv2/index.js?"+(""+date.getFullYear() + date.getMonth() + date.getDate());
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(po, s);
})();
</script>' . PHP_EOL;
return $this->sitestart;
}
}
You do not have the required permissions to view the files attached to this post.
Re: How do I execute this script?
@Omar_one, the script as amended by you worked. Thanks so much.
However, the script only output on the main index.php page. It is not visible anywhere else.
How can I make the output visible on other pages, especially on the product_info page where it is most needed? Thank you.
However, the script only output on the main index.php page. It is not visible anywhere else.
How can I make the output visible on other pages, especially on the product_info page where it is most needed? Thank you.
-
- VIP Member
- Posts: 483
- Joined: Fri Oct 25, 2019 5:06 pm
- Has thanked: 48 times
- Been thanked: 28 times
Re: How do I execute this script?
Thanks a lot @Omar_one ,
I'm using Opera(incognito), Edge & Firefox to test this. I've gotten rid of all of their caches (history, etc) and the output on all of them are still so unpredictable that I do not know if the script output will show up or not each time. Sometimes, it will show up if I type the full webpage address (..contact_us.php, ..conditions.php, etc) on the browser but even this doesn't work most of the time. This behaviour is so unbelievably erratic for me.
Could this be an issue with the OsPhoenix version I'm using? Is there any thing else that could be responsible for this weird behaviour? Thanks
-
- VIP Member
- Posts: 483
- Joined: Fri Oct 25, 2019 5:06 pm
- Has thanked: 48 times
- Been thanked: 28 times
Re: How do I execute this script?
Sorry, I can't help more, as I am not coder.
Maybe someone has more knowledge than me will give answer , or you can contact one of Certified Phoenix Cart Developers
app.php/developers
Br
Omar
Re: How do I execute this script?
@Omar_one, you've done very well and I'm so grateful. Many thanks.Omar_one wrote: ↑Thu Nov 24, 2022 6:57 pmSorry, I can't help more, as I am not coder.
Maybe someone has more knowledge than me will give answer , or you can contact one of Certified Phoenix Cart Developers
app.php/developers
Br
Omar
-
- VIP Member
- Posts: 483
- Joined: Fri Oct 25, 2019 5:06 pm
- Has thanked: 48 times
- Been thanked: 28 times
Re: How do I execute this script?
@Rich-Os
you can add pages to hook
and called Script
and change the
to
I haven't try it ,, hope this give you some idea
Br
Omar
you can add pages to hook
Code: Select all
var $good_pages = ['index.php', 'xxxx.php', 'xxxx.php']; // what pages do you want to load the livehelperchat script
Code: Select all
$livehelperchatScript = <<<eod <script>(HERE THE SCRIPT) </script>
eod;
Code: Select all
return $this->sitestart;
Code: Select all
if (in_array(basename($_SERVER['PHP_SELF']), $this->good_pages)) {
$this->sitestart .= $livehelperchatScript . PHP_EOL;
return $this->sitestart;
Br
Omar