[email protected] Posted November 5, 2013 Share Posted November 5, 2013 (edited) How to create price rules depending on time? I need to give X% discount on some categories starting 13:00 till 16:00 for example. Edited February 2, 2014 by [email protected] (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted November 5, 2013 Share Posted November 5, 2013 you can define begin / end date of price rules and cart rules too. Link to comment Share on other sites More sharing options...
PascalVG Posted November 7, 2013 Share Posted November 7, 2013 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 More sharing options...
[email protected] Posted November 15, 2013 Author Share Posted November 15, 2013 What script do I need to put in cron? Can somebody help? Link to comment Share on other sites More sharing options...
PascalVG Posted November 16, 2013 Share Posted November 16, 2013 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.phpand save. That should do the job. Let me know if it works! pascal SetCartRuleTime.php 1 Link to comment Share on other sites More sharing options...
[email protected] Posted November 16, 2013 Author Share Posted November 16, 2013 Thanks, Pascal! I'll try it and will get you know if it works. Link to comment Share on other sites More sharing options...
[email protected] Posted January 29, 2014 Author Share Posted January 29, 2014 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 More sharing options...
PascalVG Posted January 31, 2014 Share Posted January 31, 2014 Hi Astik, return code means: Crontab has been run with the -u option by a user other than root. Only root is allowed to use this option. I believe. Can you check the command you run to run the script? pascal Link to comment Share on other sites More sharing options...
[email protected] Posted February 1, 2014 Author Share Posted February 1, 2014 Hi, Pascal Yes I run command under root. /usr/bin/wget -O /dev/null -t 1 http://pushpizza.ru/config/SetCartRuleTime.php Regards Suren Link to comment Share on other sites More sharing options...
[email protected] Posted February 1, 2014 Author Share Posted February 1, 2014 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.phpResolving pushpizza.ru (pushpizza.ru)... 78.24.221.120Connecting to pushpizza.ru (pushpizza.ru)|78.24.221.120|:80... connected.HTTP request sent, awaiting response... 403 Forbidden2014-02-01 16:34:00 ERROR 403: Forbidden. Regards Suren Link to comment Share on other sites More sharing options...
[email protected] Posted February 2, 2014 Author Share Posted February 2, 2014 Hi, Pascal! I moved file SetCartRule.php to parent directory and now everything works. Thank you very much for you support! Regards Link to comment Share on other sites More sharing options...
PascalVG Posted February 2, 2014 Share Posted February 2, 2014 Perfect! Thanks for the feedback. Please mark the topic as solved (see my footer on how) Pascal Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now