Page 1 of 2

How do I execute this script?

Posted: Mon Nov 21, 2022 3:59 pm
by Rich-Os
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

Re: How do I execute this script?

Posted: Tue Nov 22, 2022 6:23 am
by heatherbell
Rich-Os wrote: Mon Nov 21, 2022 3:59 pm What do I need to do to get this script working?
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?

Posted: Tue Nov 22, 2022 2:38 pm
by Rich-Os
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.

Re: How do I execute this script?

Posted: Tue Nov 22, 2022 4:06 pm
by Omar_one
@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

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;
  }

}
55555.JPG

Re: How do I execute this script?

Posted: Wed Nov 23, 2022 4:12 pm
by Rich-Os
@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.

Re: How do I execute this script?

Posted: Wed Nov 23, 2022 5:05 pm
by Omar_one
Rich-Os wrote: Wed Nov 23, 2022 4:12 pm How can I make the output visible on other pages, especially on the product_info page where it is most needed?
it's shown in all the pages on my test

Re: How do I execute this script?

Posted: Thu Nov 24, 2022 2:45 pm
by Rich-Os
Omar_one wrote: Wed Nov 23, 2022 5:05 pm
Rich-Os wrote: Wed Nov 23, 2022 4:12 pm How can I make the output visible on other pages, especially on the product_info page where it is most needed?
it's shown in all the pages on my test
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

Re: How do I execute this script?

Posted: Thu Nov 24, 2022 6:57 pm
by Omar_one
Rich-Os wrote: Thu Nov 24, 2022 2:45 pm 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
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?

Posted: Tue Nov 29, 2022 12:40 pm
by Rich-Os
Omar_one wrote: Thu Nov 24, 2022 6:57 pm
Rich-Os wrote: Thu Nov 24, 2022 2:45 pm 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
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
@Omar_one, you've done very well and I'm so grateful. Many thanks.

Re: How do I execute this script?

Posted: Tue Nov 29, 2022 6:43 pm
by Omar_one
@Rich-Os
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 
and called Script

Code: Select all

 $livehelperchatScript = <<<eod <script>(HERE THE SCRIPT) </script>
eod; 
and change the

Code: Select all

 return $this->sitestart;
to

Code: Select all

if (in_array(basename($_SERVER['PHP_SELF']), $this->good_pages)) {	
 $this->sitestart .= $livehelperchatScript . PHP_EOL;
    return $this->sitestart;
I haven't try it ,, hope this give you some idea

Br
Omar