Originally Posted by
CaroleAs
I think a simple module to do that would be welcome!!!
New file:
includes/init_includes/init_special_funcs_disabled_upcoming.php
Code:
<?php
/**
* @copyright 2018
* @license http://www.zen-cart.com/License/2_0.txt GNU Public License V2.0
* @author mc12345678
**/
if (!isset($_SESSION['today_is'])) {
$_SESSION['today_is'] = date('Y-m-d');
}
if ($_SESSION['today_is'] != date('Y-m-d')) {
$_SESSION['today_is'] = date('Y-m-d');
$_SESSION['updateExpirations_upcoming'] = false;
}
if (!isset($_SESSION['updateExpirations_upcoming']) || $_SESSION['updateExpirations_upcoming'] !== true) {
/**
* require the disabled upcoming products functions, auto-enable disabled product.
*/
require DIR_WS_FUNCTIONS . 'disabled_upcoming.php';
zen_enable_disabled_upcoming();
}
new file:
includes/functions/disabled_upcoming.php
Code:
<?php
/**
* disabled-upcoming products functions
*
* @copyright 2018
* @license http://www.zen-cart.com/License/2_0.txt GNU Public License V2.0
* @author mc12345678
**/
function zen_set_disabled_upcoming_status($products_id, $status) {
$sql = "UPDATE " . TABLE_PRODUCTS . "
SET products_status = " . (int)$status . ", products_date_available = '0001-01-01' WHERE products_id = " . (int)$products_id;
return $GLOBALS['db']->Execute($sql);
}
function zen_enable_disabled_upcoming() {
$date_range = time();
$zc_disabled_upcoming_date = date('Ymd', $date_range);
$disabled_upcoming_query = "SELECT products_id
FROM " . TABLE_PRODUCTS . "
WHERE products_status = 0
AND ((products_date_available <= " . $zc_disabled_upcoming_date . "
AND products_date_available != '0001-01-01'))
";
$disabled_upcoming = $GLOBALS['db']->Execute($disabled_upcoming_query);
if ($disabled_upcoming->RecordCount() > 0) {
while (!disabled_upcoming->EOF) {
zen_set_disabled_upcoming_status($disabled_upcoming->fields['products_id'], 1);
$disabled_upcoming->MoveNext();
}
}
}
Then to initiate the above code (saved for last to tie it together), add the following new file:
includes/auto_loaders/config.enable_disabled_upcoming.php
Code:
<?php
/**
* disabled-upcoming products auto_loader to execute the operations.
*
* @copyright 2018
* @license http://www.zen-cart.com/License/2_0.txt GNU Public License V2.0
* @author mc12345678
**/
/**
*Load just before the other special functions that may include this product.
*/
$autoLoadConfig[149][] = array(
'autoType'=>'init_script',
'loadFile'=>'init_special_funcs_disabled_upcoming.php',
);
Note, there is no "do this for this product, but not that product" type switch incorporated. Ie. any product that has a products_date_available that has passed will be so enabled and the products_date_available will be set/reset to 0001-01-01 as if it never had such a future date...
Bookmarks