Post by originalstormcrow » Sun May 26, 2019 2:18 am

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.


Posts

Joined
Fri Apr 14, 2017 12:07 pm

Post by uksitebuilder » Sun May 26, 2019 4:45 am

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

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by straightlight » Sun May 26, 2019 8:21 am

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.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by grgr » Sun May 26, 2019 10:31 am

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.

Image Image Image Image Image Image Image Image


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by straightlight » Sun May 26, 2019 11:58 pm

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.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Opencart.com Administrator / Quality Assurance Analyst / Programmer


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Johnathan » Mon May 27, 2019 9:41 pm

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.

Image
Image Image Image Image


User avatar
Global Moderator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: Bing [Bot] and 48 guests