Zen Cart Logo
Forums / General Questions / changing the greeting

changing the greeting

Views: 796

Results 1 to 7 of 7
11 Sep 2015, 11:48 AM
#1
adb34 avatar

adb34

Totally Zenned

Join Date:
Mar 2008
Location:
Brampton, Cumbria, United Kingdom, United Kingdom
Posts:
825
Plugin Contributions:
0

changing the greeting

I am wanting to change to greeting on the home page to include the part of the day the customer is in for example if it is 2pm the greeting is Good afternoon and then either guest or their first name.

I have been looking for php annotations. Can someone suggest a good place to look?

Thanks

11 Sep 2015, 12:37 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: changing the greeting

Not familiar with the term php annotations. What is it that it is to imply?

Also, on what are you basing the time of day? Is it server time? Doing a locality check based on ip address or something? Allowing the logged in customers to choose their time zone?

Almost don't want to ask, but from an operatons perspective what financial benefit is this feature?

11 Sep 2015, 2:58 PM
#3
adb34 avatar

adb34

Totally Zenned

Join Date:
Mar 2008
Location:
Brampton, Cumbria, United Kingdom, United Kingdom
Posts:
825
Plugin Contributions:
0

Re: changing the greeting

I have got the first bit sorted.```html
<html>
<body>

<script type="text/javascript">
var d = new Date();
var time = d.getHours();

if (time < 12) 
  {
  document.write("<b>Good morning!</b>");
  }
if (time > 12 & time <18) 
  {
  document.write("<b>Good afternoon!</b>");
  }
if (time > 12) 
  {
  document.write("<b>Good Evening</b>");
  }
</script>

</body>

</html>
11 Sep 2015, 8:11 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: changing the greeting

Couple of things, this is all javascript and therefore don't see the tie yet to php annotations, but that said you'll be wanting to interact with other classes/ids already on the page. If they are not there yet, then will need to add them to the applicable code.

The other thing is that the construct provided if not mistaken is still server locale date/time specific not local to the customer accessing the site. This is fine if only customers that are in your local timezone are the ones accessing (allowed to access) your site, otherwise someone in a different timezone will see the wrong representaton. Also, t appears that from 1200 to 1259 there is no representation. Suggest making the second if >= 12 & < 18

12 Sep 2015, 9:40 AM
#5
adb34 avatar

adb34

Totally Zenned

Join Date:
Mar 2008
Location:
Brampton, Cumbria, United Kingdom, United Kingdom
Posts:
825
Plugin Contributions:
0

Re: changing the greeting

mc12345678:

Couple of things, this is all javascript and therefore don't see the tie yet to php annotations, but that said you'll be wanting to interact with other classes/ids already on the page. If they are not there yet, then will need to add them to the applicable code.

Sorry, I forgot to put 'I have found a JavaScript that can do what I am asking'.

mc12345678:

The other thing is that the construct provided if not mistaken is still server locale date/time specific not local to the customer accessing the site. This is fine if only customers that are in your local timezone are the ones accessing (allowed to access) your site, otherwise someone in a different timezone will see the wrong representaton. Also, t appears that from 1200 to 1259 there is no representation. Suggest making the second if >= 12 & < 18

I found the code on the W3 Schools website. The thing with your statement 12:01 is greater than 12:00

12 Sep 2015, 11:49 AM
#6
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: changing the greeting

adb34:

I found the code on the W3 Schools website. The thing with your statement 12:01 is greater than 12:00

So where time = d.getHours(); if it is 12:01 then time will be 12:01 and not just 12?

I'm sorry that I don't have the solution specifically, but am trying to understand and to close what looks like the issues. In looking for a way to present the time to a customer I was surprised to find code on stackexchange indicating that it was necessary to convert the returned date() value to the time local to the user as java/javascript is supposed to be all about the user's side. But not infallible resources. No conversion appears to be necessary for the date/time, but d.getHours() will return a whole number and therefore between 12:00 and 12:59 the. Variable time will equal 12 which is not specifically captured in the above code.

12 Sep 2015, 1:41 PM
#7
adb34 avatar

adb34

Totally Zenned

Join Date:
Mar 2008
Location:
Brampton, Cumbria, United Kingdom, United Kingdom
Posts:
825
Plugin Contributions:
0

Re: changing the greeting

mc12345678:

So where time = d.getHours(); if it is 12:01 then time will be 12:01 and not just 12?

I'm sorry that I don't have the solution specifically, but am trying to understand and to close what looks like the issues. In looking for a way to present the time to a customer I was surprised to find code on stackexchange indicating that it was necessary to convert the returned date() value to the time local to the user as java/javascript is supposed to be all about the user's side. But not infallible resources. No conversion appears to be necessary for the date/time, but d.getHours() will return a whole number and therefore between 12:00 and 12:59 the. Variable time will equal 12 which is not specifically captured in the above code.

All true and I do appreciate all your help on all topics. I think I will put this on hold until I have sorted out the other stuff that is needed E.G. cookie control Etc.