Page 1 of 1
Have product enabled & disabled based on time of day
Posted: Sun May 26, 2019 2:18 am
by originalstormcrow
Does anyone know of an extension the turns a product availability off at a certain time of day, and then back on at another.
Not having much luck finding one.
Re: Have product enabled & disabled based on time of day
Posted: Sun May 26, 2019 4:45 am
by uksitebuilder
You will probably need a script to be run by cron job on the time(s) that you wish enable or disable products.
The script is quite simple. Something like: status.php in your store root
Code: Select all
<?php
if(isset($_GET['status']) && ($_GET['status'] === 1 || $_GET['status'] === 0)){
$status = (int)$_GET['status'];
set_time_limit(0);
require_once('config.php');
require_once(DIR_SYSTEM . 'startup.php');
// Registry
$registry = new Registry();
// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);
// Config
$config = new Config();
$registry->set('config', $config);
// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);
// Create products array
$products = array();
// example -> $products[] = 1;
foreach ($products as $product){
$query = $db->query("UPDATE `" . DB_PREFIX . "product` SET `status` = $status WHERE `product_id` = '$product'");
}
}
Then you can run the script via cron, e.g. yourdomain.com/status.php?status=1 to enable or replace 1 with 0 to disable
Don’t forget to add as many $products[] as you wish with the appropriate product_id's
Re: Have product enabled & disabled based on time of day
Posted: Sun May 26, 2019 8:21 am
by straightlight
if(isset($_GET['status']) && ($_GET['status'] === 1 || $_GET['status'] === 1)){
Required to be validated twice? Another way, however, would be by creating an event file since OC already allows it on more recent releases.
Re: Have product enabled & disabled based on time of day
Posted: Sun May 26, 2019 10:31 am
by grgr
An event file won't help much as this is the 1.5x forum.
All products or just specific products?
Prevent adding to cart only or hide the product?
Can I ask why.....? Knowing why can help with an answer.
Re: Have product enabled & disabled based on time of day
Posted: Sun May 26, 2019 11:58 pm
by straightlight
An event file won't help much as this is the 1.5x forum.
Yes, which is why I mentioned 'on more recent releases' from my previous reply.
Re: Have product enabled & disabled based on time of day
Posted: Mon May 27, 2019 9:41 pm
by Johnathan
You could do this with
Restrict Checkout. You'd set up 2 restrictions like this, to disable the checkout when Product A was being purchased before 8:00 am or after 5:00 pm:
------------------------------------------------------------------------------
RESTRICTION #1
Name: Disable checkout when Product A is purchased during closed hours
Message: This product must be purchased between 8:00 am and 5:00 pm
Rule: Product is Product A
Rule: Time is before 08:00
RESTRICTION #2
Name: Disable checkout when Product A is purchased during closed hours
Message: This product must be purchased between 8:00 am and 5:00 pm
Rule: Product is Product A
Rule: Time is after 17:00
------------------------------------------------------------------------------
Feel free to take a look at the screenshots and demo site, and if you're interested let me know at
www.getclearthinking.com/contact if you have any further questions.