Forums / General Questions / Working hours...

Working hours...

Locked

Started by gyurci on 13 Mar 2009, 9:25 PM · Views: 1,619

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
13 Mar 2009, 9:25 PM
#1
gyurci avatar

gyurci

New Zenner

Join Date:
Mar 2009
Posts:
5
Plugin Contributions:
0

Working hours...

Hi Folks,
I would like to restrict my store. Orderings need to possible only in working hours. I am just testing the latest Zen Cart version, before use it in real environment, but it is very important aspect for me. Could anybody suggest method, links etc.

Thanks in advanced,

Gyurci

13 Mar 2009, 9:55 PM
#2
website_rob avatar

website_rob

Inactive

Join Date:
Oct 2006
Location:
Alberta, Canada
Posts:
4,572
Plugin Contributions:
0

Re: Working hours...

Hi and Welcome to the Forum. :smile:

Till you find something different the easiest way is to manually put the Store in Maintenance mode, then enable Store when open again.

Admin > Configuration > Website Maintenance

The learning is in the doing.

Potent Products

13 Mar 2009, 10:42 PM
#3
steven300 avatar

steven300

Totally Zenned

Join Date:
Jan 2008
Posts:
1,564
Plugin Contributions:
1

Re: Working hours...

I would create two php files. One contains an sql statement to put the store in showcase mode. The other contains an sql statement to put the store in normal mode. Then create two cron jobs to call the files at the appropriate times.

13 Mar 2009, 11:40 PM
#4
gyurci avatar

gyurci

New Zenner

Join Date:
Mar 2009
Posts:
5
Plugin Contributions:
0

Re: Working hours...

Website Rob and Steven300,
thanks for your quick help. Theoretically I totally understand Steven300's solution and it is very creative, but I am a graphic designer and I have no programming knowledge at all. :(
So with PhpMyadmin I can find in configuration table the Store Status value but I can not write a PHP code to change it.
Could you give me some cue words what should I search in PHP help or forums. I definitely like to solve this problem so if I have to learn, I will do that. Please correct me if I wrong, I should connect to the local database, make a value change in a table and close the connection. Can I make it only with the built in PHP functions?
The two php files should be in public_html folder or not?

Thanks and have a nice day!

Gyurci

14 Mar 2009, 12:16 AM
#5
steven300 avatar

steven300

Totally Zenned

Join Date:
Jan 2008
Posts:
1,564
Plugin Contributions:
1

Re: Working hours...

I think it would go something like this..

<?php

require('includes/application_top.php');

$sql="UPDATE configuration SET configuration_value = 2 where configuration_id = 23;";

$result=$db->Execute($sql);

?>

Including application_top.php will automatically connect you to the database. The example above puts the store in showcase mode (with prices). To put it in normal mode, you would change configuration_value from 2 to 0. This example assumes the file is in your root directory. I think you could put it elsewhere providing you update the path to application_top.php. Hope this helps.

14 Mar 2009, 12:54 AM
#6
steven300 avatar

steven300

Totally Zenned

Join Date:
Jan 2008
Posts:
1,564
Plugin Contributions:
1

Re: Working hours...

Or if you wanted to avoid cron jobs for whatever reason, you could take a different approach whereby you create a php file containing the following code and include it so it loads on each page visit to your site. It gets the current time and checks to see whether the store should be in normal mode or showcase mode and sets it accordingly. I'm not sure whether it would affect the speed of your site doing this on each page visit, but I think it should be okay.

<?php

require('includes/application_top.php');

//Define opening time
$opening_time = "09:00:00";
$closing_time = "17:00:00";

//Remove characters
$opening_time = str_replace(':', '', $opening_time);
$closing_time = str_replace(':', '', $closing_time);

//Get current time
$t = time();
$now = date('His', $t);

//Check if it's opening time
if ( ($now > $opening_time ) && ( $now < $closing_time ) ) {
//opening time, put store in normal mode
$sql_opening="UPDATE configuration SET configuration_value = 0 where configuration_id = 23;";
$result_opening=$db->Execute($sql_opening);
} else {
//closing time, put store in showcase mode
$sql_closing="UPDATE configuration SET configuration_value = 2 where configuration_id = 23;";
$result_closing=$db->Execute($sql_closing);
}

?>
14 Mar 2009, 1:07 AM
#7
gyurci avatar

gyurci

New Zenner

Join Date:
Mar 2009
Posts:
5
Plugin Contributions:
0

Re: Working hours...

I am in late because of test Your first method. At first sight it not worked for me because I put a pre (zen) tag to my all table at installation and I forgot about it. But now everything works fine.
Absolutelly You are the king. :yes:

I will try Your second method in a minute. Thanks for Your help.

Best regards,

Gyurci

14 Mar 2009, 1:40 AM
#8
gyurci avatar

gyurci

New Zenner

Join Date:
Mar 2009
Posts:
5
Plugin Contributions:
0

Re: Working hours...

It's an another brilliant solution!

" create a php file containing the following code"
for example changemod.php

"and include it "
to where? You mean I should place this row "require('changemod.php');"to every visible php file on my webpage?! Tell the truth, this is my first try with Zen Cart, so I can not know the stucture pretty much.

Just a quick tip in theoretically:
May be I should only include this file to the index.php, so the first visitor will turn off the store shopping cart in the closed time, and vica versa. Is it true, that Your function works only when someone calls in my case the index.php from a web browser?

Bye,

Gyurci

14 Mar 2009, 2:08 AM
#9
steven300 avatar

steven300

Totally Zenned

Join Date:
Jan 2008
Posts:
1,564
Plugin Contributions:
1

Re: Working hours...

To be honest I'm still learning about the Zen Cart structure as well, especially when it comes to auto-loading. My (minimal) understanding of index.php is that it is like the "engine" for Zen Cart and is used to "put together" every page. So you might find that including it from index.php will load it on every page visit, not just the first. Hopefully someone more experienced in this area can jump in.

14 Mar 2009, 2:13 AM
#10
gyurci avatar

gyurci

New Zenner

Join Date:
Mar 2009
Posts:
5
Plugin Contributions:
0

Re: Working hours...

Thanks once more, You solved my problem in a minute.
The cron version absolute perfect for me.

Good luck!

Gyurci

14 Mar 2009, 2:15 AM
#11
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Working hours...

Absolutely don't go changing index.php unless you have a really good understanding of what you're doing. A much more correct place to include this code would be in a file over-riding the the init_customer_auth script in the includes/init_includes folder.

Kuroi Web Design and Development | Twitter

(Questions answered in the forum only - so that any forum member can benefit - not by personal message)