How do I execute this script?

Ask the community for help and support.
Rich-Os
Posts: 10
Joined: Thu Sep 30, 2021 2:03 pm
Has thanked: 4 times

How do I execute this script?

Post 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
Last edited by Rich-Os on Mon Nov 21, 2022 9:57 pm, edited 2 times in total.
heatherbell
VIP Member
VIP Member
Posts: 1996
Joined: Mon Oct 07, 2019 4:39 am
Has thanked: 26 times
Been thanked: 175 times

Re: How do I execute this script?

Post 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
Rich-Os
Posts: 10
Joined: Thu Sep 30, 2021 2:03 pm
Has thanked: 4 times

Re: How do I execute this script?

Post 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.
Omar_one
VIP Member
VIP Member
Posts: 481
Joined: Fri Oct 25, 2019 5:06 pm
Has thanked: 48 times
Been thanked: 27 times

Re: How do I execute this script?

Post 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
You do not have the required permissions to view the files attached to this post.
Rich-Os
Posts: 10
Joined: Thu Sep 30, 2021 2:03 pm
Has thanked: 4 times

Re: How do I execute this script?

Post 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.
Omar_one
VIP Member
VIP Member
Posts: 481
Joined: Fri Oct 25, 2019 5:06 pm
Has thanked: 48 times
Been thanked: 27 times

Re: How do I execute this script?

Post 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
Rich-Os
Posts: 10
Joined: Thu Sep 30, 2021 2:03 pm
Has thanked: 4 times

Re: How do I execute this script?

Post 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
Omar_one
VIP Member
VIP Member
Posts: 481
Joined: Fri Oct 25, 2019 5:06 pm
Has thanked: 48 times
Been thanked: 27 times

Re: How do I execute this script?

Post 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
Rich-Os
Posts: 10
Joined: Thu Sep 30, 2021 2:03 pm
Has thanked: 4 times

Re: How do I execute this script?

Post 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.
Omar_one
VIP Member
VIP Member
Posts: 481
Joined: Fri Oct 25, 2019 5:06 pm
Has thanked: 48 times
Been thanked: 27 times

Re: How do I execute this script?

Post 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
Post Reply