Jump to content

[SOLVED] Carrier options based on time of day


birdmarketing

Recommended Posts

Hello I want to enable/disable carrier options based on what time of the day it is.

 

I believe I should start from here: 

themes/default/order-carrier.tpl

However I am not familiar with using php in .tpl files and I am unsure on how to call the carrier IDs through php on prestashop.

 

I am pretty sure once I overcome these issues it will just be a matter of a simple IF statement that checks the time and if it is within the time zones then I can enable the particular carrier option.

 

There are multiple carrier options available at particular times of the day.

 

If anyone could help me with these issues then I would greatly appreciate it.

 

Thanks for all your help,

Phil.

Edited by philipryoung (see edit history)
Link to comment
Share on other sites

Hi Phil,

 

The time zones, are they CLIENT specific, or YOUR location specific?

If it's just your single time specific, It's probably the easiest to make a crob job, which turns on/off a carrier dependent on the time of day,day of week etc. using some SQL statement:

First check if your Host allows you to run cron jobs.

If so, add the following two cron jobs and scripts:

Create an empty file 'DisableCarrier.php' in /<root of shop>/config/ folder.

Edit file and copy this in there:

 

<?php

 

// cron job php script to disable carrier

 

// by Pascal van Geest @ ModulesModules.com

 

// Setup connection variables, such as database username

 

// and password

 

// host name, database user, password and database name

 

// can be found in:

 

// config/settings.inc.php

 

$hostname="localhost";

 

$username="your user name of the database used";

 

$password="the password of that user";

 

$dbname="database name";

 

//Connect to the database

 

$connection = mysql_connect($hostname, $username, $password);

 

mysql_select_db($dbname, $connection);

 

 

 

//Setup our query

 

$query ="UPDATE `ps_carrier` SET `value` = 0 where `name` = '<add here the name of the carrier>';";

 

 

 

//Run the Query

 

$result = mysql_query($query);

 

?>

Add info of hostname, database, user, password (see your config/settings.inc.php file for these details)

and save the file.

 

Then go to your cPanel and go to Cron Jobs application.

Add a new cron job:

Select MINUTE = 0 (to close straight on the hour)

HOUR = 19 (example, to disable the carrier at 7 PM)

select DAY = * (if you want to disable the carrier every day)

select MONTH = *

select WEEKDAY = * ( if you work all days)

 

add command:

/usr/bin/php full/path/to/your/new/file/DisableCarrier.php

and save.

 

Same to Enable the carrier again:

Create new file EnableCarrier.php in the /<root of shop>/config/ folder.

edit and copy this:

<?php

 

// cron job php script to enable a carrier

 

// by Pascal van Geest @ ModulesModules.com

 

// Setup connection variables, such as database username

 

// and password

 

// host name, database user, password and database name

 

// can be found in:

 

// config/settings.inc.php

 

$hostname="localhost";

 

$username="your user name of the database used";

 

$password="the password of that user";

 

$dbname="database name";

 

//Connect to the database

 

$connection = mysql_connect($hostname, $username, $password);

 

mysql_select_db($dbname, $connection);

 

 

 

//Setup our query

 

$query ="UPDATE `ps_carrier` SET `value` = 1 where `name` = '<the name of the carrier>';";

 

 

 

//Run the Query

 

$result = mysql_query($query);

 

?>

Add info of hostname, database, user, password (see config//settings.inc.php for details)

and save file

 

make another cron job, to enable the carrier again:

 

 

Select MINUTE = 30 (example, to enable at half past...)

HOUR = 8 (example, to enable at 8:30 am)

select DAY = * (if you want to enable the carrier every day)

select MONTH = *

select WEEKDAY = * ( if you work all days)

 

add command:

/usr/bin/php full/path/to/your/new/file/EnableCarrier.php

and save.

 

 

To see if it works, change the MINUTE AND HOUR temporarily to * (One job only, first cronjob of DisableCarrier.php. if that does the job (Check by waiting 1 minute and then reload (Ctrl-F5) the Carrier list. See if Status is disabled(Crossed out)) , change this job back to real disabling time and then change the EnableCarrier cron job to * for MINUTE and HOUR. If it reopens again (check again by waiting 1 minute and reload (Ctrl-F5) the carrier list page), change to the real enabling times again.

 

Hope this helps,

pascal

  • Like 2
Link to comment
Share on other sites

That was one of the most helpful answers I could have possibly expected. You have saved me hours of working on the wrong thing and pointed me in the right direction.

 

I did however make an edit (in case anyone needed anything of a similar sort):

 

I used the following command to change the database values

$query ="UPDATE ps_carrier SET active=0 WHERE id_carrier=3;";

and I also had to put "php " in front of the cron job to stop it from running the file as a shell script.

 

Another thing I had to look out for was making sure the system time was set correctly.

 

Thank-you ever so much for all of your help.

Link to comment
Share on other sites

Hi Phil,

Sure id_carrier is also possible, a little less readable when maintaining though, so I chose the name :-)

 

Yes, if you look carefully, there's a usr/bin/php before the path to the script, to run it. That's needed to make it work :-)

 

Glad it worked for you!

Pascal

  • Like 1
Link to comment
Share on other sites

  • 4 months later...
  • 6 months later...

Hi Pascal,

Thanks for this solution. I have a question related to this. it seems is not finding the file i place in the cron job. can you explain me when you say

add command:
/usr/bin/php full/path/to/your/new/file/DisableCarrier.php
 

I used 

/usr/bin/php/tienda/config/Disablecarrier.php

 

that is where my file is and it says it cant find it.

 

Thank you very much,

 

Carlos

Link to comment
Share on other sites

Two checks:

Did you add the first part (usr/bin/php  )?

 

check your permissions of the file DisbleCarrier.php (should be '644' or '755' or so)   (And check your Captials, as you wrote Disablecarrier.php in the path, but maybe the file itself is DisableCarrier.php ?? (The file name is case sensitive!!)

 

 

Hope this helps,

pascal

Link to comment
Share on other sites

Two checks:

Did you add the first part (usr/bin/php  )?

 

check your permissions of the file DisbleCarrier.php (should be '644' or '755' or so)   (And check your Captials, as you wrote Disablecarrier.php in the path, but maybe the file itself is DisableCarrier.php ?? (The file name is case sensitive!!)

 

 

Hope this helps,

pascal

Hi Pascal,

I did not add that (usr/bin/php  )part

on the other side I have the 755 permissions

 

I checked the spelling and it is OK  

the notification I got on my email is this

 

/usr/local/cpanel/bin/jailshell: tienda/config/DisableCarrierInmediato.php: No such file or directory

 

 

Do you know what the problem is?

 

 

Thank You

 

Carlos

Link to comment
Share on other sites

Hey there, maybe this will help you.

I use the '-q' and it works well on centos server:

/usr/bin/php -q /home/CPANEL NAME HERE/public_html/...

 

For you that would be:

/usr/bin/php -q /home/CPANEL NAME HERE/public_html/tienda/config/DisableCarrierInmediato.php

Link to comment
Share on other sites

Hey there, maybe this will help you.

I use the '-q' and it works well on centos server:

/usr/bin/php -q /home/CPANEL NAME HERE/public_html/...

 

For you that would be:

/usr/bin/php -q /home/CPANEL NAME HERE/public_html/tienda/config/DisableCarrierInmediato.php

Hi,

Thanks for your reply I dont know what im doing wrong.  I am supposed to place that whole line inside the Command line in the cron job in Cpanel right?   I used it and know I got this  No input file specified.

Link to comment
Share on other sites

you need the php file in its absolute location which will be /home/CPANE NAME/public_html...

 

The line i posted will not work for you. The line needs to have your cPanel name in it. This would be different for everyone.

 

If you are not sure what your cPanel name is, log into cPanel and have a look on the first page when you log in. There should be a little info box / windows which is named 'Stats'. in there will be 'Home Directory'.

 

Behind that is the path beginning including cPanel name, such as '/home/yourName

 

Now stick that into the front like this:

/usr/bin/php -q /home/yourName/public_html/tienda/config/DisableCarrierInmediato.php

 

Hope this helps

Link to comment
Share on other sites

thanks a lot for your help. It seems it found the file but I still have issues

 

look what it is sending now

 

/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 1: ?php: No such file or directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 3: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 5: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 7: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 9: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 11: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 13: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 15: //: Is a directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 17: =localhost: command not found
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 19: =whisky8_whisky: command not found
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 21: =B.jJ.8P63S: command not found
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 23: =whisky8_whisky: command not found
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 25: //Connect: No such file or directory
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 27: syntax error near unexpected token `('
/home/whisky8/public_html/tienda/config/DisableCarrierInmediato.php: line 27: `$connection = mysql_connect($hostname, $username, $password);'

 

 

Do you know what to do?

 

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...