Jump to content

[SOLVED] Price Rules depending on time


astik1969@gmail.com

Recommended Posts

But this would only work for one day, so you have to come back each day to change it...

 

Maybe some cron job would work here, where you let it change the valid from/to dates, setting them to the 'current day' or so. (In the cron job definition, you could even indicate to only do this on weekdays, or only monday/wednesday/friday etc. The cron job timer is quite flexible in this.)

 

 

My 2 cents,

pascal

Link to comment
Share on other sites

  • 2 weeks later...

Hi astik,

 

try this:

 

First in your database, have a look at table ps_cart_rule

Find the cart rule row that contains the definition of the rule you want to update every day.

Remember the cart_rule_id (found in the first column) of that row. (Should be an integer number)

 

Download the attached file and open in a text editor.

Open de file config/settings.inc.php on your server, and copy from here the host name, database name, login name and password into the earlier opened file.

 

Example info from settings.inc.php:

 

define('_DB_SERVER_', 'localhost');
define('_DB_NAME_', 'mydatab5');
define('_DB_USER_', 'mydatab_usr1');
define('_DB_PASSWD_', 'lPg000892D');
 

Copy this to the file:

 

$hostname="localhost";
$dbname="mydatab5";
$username="mydatab_usr1";
$password="lPg000892D";
 

 

Then, in the file you see the following line:

 

$query = "UPDATE `ps_cart_rule` SET `date_from`=CURDATE() + INTERVAL 13 HOUR,   `date_to`= CURDATE() + INTERVAL 1 DAY + INTERVAL 16 HOUR WHERE `id_cart_rule` = XXX;";
 
Replace XXX with the cart_rule_id you remembered before so you get something like:
 
$query = "UPDATE `ps_cart_rule` SET `date_from`=CURDATE() + INTERVAL 13 HOUR,   `date_to`= CURDATE() + INTERVAL 16 HOUR WHERE `id_cart_rule` = 12;";
 
 
The 13 and 16 in this line are the times you want the cart rule be valid. The day it will be valid is "TODAY", from 13:00 until 16:00 hours. If you want other hours, just change accordingly.
 
 
Save your file. Then upload it to your /config folder.
 

The cronjob needed to add, looks like this: (in my example, it updates the validity time at 9:00 (But the valid time is still 13:00 - 16:00. So just make sure you update before 13:00 hours)

 

Then go to your cPanel and go to Cron Jobs application.
Add a new cron job:
Select MINUTE = 0 (we update straight on the hour)
HOUR = 9 (example, to update at 9:00 AM)
select DAY = * (if you want to update every day)
select MONTH = *
select WEEKDAY = *

 

 

add command:
    /usr/bin/php  full/path/to/your/new/file/SetCartRuleTime.php
and save.

 

 

That should do the job. Let me know if it works!

 

pascal

 

SetCartRuleTime.php

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

Hi Pascal!

 

I made everything like you wrote but it doesn't work. When I run cron job it gives me: Exited with return code = 8 

 

and doesn't change my cart rule.

 

My file looks like:

 

<?php

 
// cron job php script to set shop into maintenance mode
// by Pascal van Geest @ ModulesModules.com
// use with cron job string like this:
// 
 
//Setup connection variables, such as database username
//and password
$hostname="localhost";
$dbname="***";
$username="***";
$password="***";
 
//Connect to the database
$connection = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname, $connection);
 
//Setup our query
$query = "UPDATE `ps_cart_rule` SET `date_from`=CURDATE() + INTERVAL 10 HOUR,   `date_to`= CURDATE() + INTERVAL 16 HOUR WHERE `id_cart_rule` = 167;";
 
//Run the Query
$result = mysql_query($query);
 
?>
 
What to do?
 
Regards
Link to comment
Share on other sites

This I get from console:

 

root@pushpizza:~# /usr/bin/wget -O /dev/null -t 1 http://pushpizza.ru/config/SetCartRuleTime.php
--2014-02-01 16:34:00-- http://pushpizza.ru/config/SetCartRuleTime.php
Resolving pushpizza.ru (pushpizza.ru)... 78.24.221.120
Connecting to pushpizza.ru (pushpizza.ru)|78.24.221.120|:80... connected.
HTTP request sent, awaiting response... 403 Forbidden
2014-02-01 16:34:00 ERROR 403: Forbidden. 

 

Regards

Suren

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...