Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide product from cart until available date.. #2720

Merged
merged 19 commits into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions includes/functions/functions_products.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,30 @@ function zen_product_set_header_response($product_id, $product_info = null)

if ($response_code === 200) return;
}

function zen_set_disabled_upcoming_status($products_id, $status) {
$sql = "UPDATE " . TABLE_PRODUCTS . "
SET products_status = " . (int)$status . ", products_date_available = '0001-01-01 00:00:00' 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);

foreach ($disabled_upcoming as $disabled_upcoming_fields) {
zen_set_disabled_upcoming_status($disabled_upcoming_fields['products_id'], 1);
}
}
66 changes: 38 additions & 28 deletions includes/init_includes/init_special_funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,66 @@
* @copyright Copyright 2003-2012 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version GIT: $Id: Author: Ian Wilson Tue Jul 24 11:36:47 2012 +0100 Modified in v1.5.1 $
* @version GIT: $Id: Author: Ian Wilson Tue Jul 24 11:36:47 2012 +0100 Modified in v1.5.1 $
*/
if (!defined('IS_ADMIN_FLAG')) {
die('Illegal Access');
die('Illegal Access');
}
/**
* require the whos online functions and update
*/
require(DIR_WS_FUNCTIONS . 'whos_online.php');
require DIR_WS_FUNCTIONS . 'whos_online.php';
zen_update_whos_online();
/**
* require the banner functions, auto-activate and auto-expire
*/
require(DIR_WS_FUNCTIONS . 'banner.php');
require DIR_WS_FUNCTIONS . 'banner.php';
zen_activate_banners();
zen_expire_banners();
/**
* require product functions one time such that if previously loaded will not cause an error here.
*/
require_once DIR_WS_FUNCTIONS . 'functions_products.php';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mc12345678
Given that init_general_funcs.php already has a require for functions_products.php which loads at breakpoint 60, why are we requiring it again here again in init_speical_funcs.php which loads at breakpoint 150?

Ref: #2551

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In essence, to allow such a comment/question/tracking to identify the dependency of these changes on functions_products.php... Possibly could have just added a note to indicate that dependency; however, also wanted to be sure that it was actually included at or before the subsequent code in the event the file's load point was otherwise changed. I recall there being some "adjustments" being made to its (functions_products.php) load point and/or inclusion.

As a "final product" I would say that identifying the dependency as a code comment should be sufficient and that the line could otherwise be removed.

/**
* only process once per session do not include banners as banners expire per click as well as per date
* require the banner functions, auto-activate and auto-expire.
*
* this is processed in the admin for dates that expire while being worked on
*/
// check if a reset on one time sessions settings should occur due to the midnight hour happening
if (!isset($_SESSION['today_is'])) {
if (!isset($_SESSION['today_is'])) {
$_SESSION['today_is'] = date('Y-m-d');
}
if ($_SESSION['today_is'] != date('Y-m-d')) {
}
if ($_SESSION['today_is'] != date('Y-m-d')) {
$_SESSION['today_is'] = date('Y-m-d');
$_SESSION['updateExpirations'] = false;
}
}
if (!isset($_SESSION['updateExpirations']) || $_SESSION['updateExpirations'] !== true) {
/**
* require the specials products functions, auto-activate and auto-expire
*/
require(DIR_WS_FUNCTIONS . 'specials.php');
zen_start_specials();
zen_expire_specials();
/**
* require the featured products functions, auto-activate and auto-expire
*/
require(DIR_WS_FUNCTIONS . 'featured.php');
zen_start_featured();
zen_expire_featured();
/**
* require the salemaker functions, auto-activate and auto-expire
*/
require(DIR_WS_FUNCTIONS . 'salemaker.php');
zen_start_salemaker();
zen_expire_salemaker();
/**
* enable disabled product that have a historical products_available_date to become active
* in advance of other product handlers to prepare the product for use in those handlers.
*/
if (defined('ENABLE_DISABLED_UPCOMING_PRODUCT') && ENABLE_DISABLED_UPCOMING_PRODUCT == '1') {
zen_enable_disabled_upcoming();
}
/**
* require the specials products functions, auto-activate and auto-expire
*/
require DIR_WS_FUNCTIONS . 'specials.php';
zen_start_specials();
zen_expire_specials();
/**
* require the featured products functions, auto-activate and auto-expire
*/
require DIR_WS_FUNCTIONS . 'featured.php';
zen_start_featured();
zen_expire_featured();
/**
* require the salemaker functions, auto-activate and auto-expire
*/
require DIR_WS_FUNCTIONS . 'salemaker.php';
zen_start_salemaker();
zen_expire_salemaker();

$_SESSION['updateExpirations'] = true;
$_SESSION['updateExpirations'] = true;
}
?>
2 changes: 2 additions & 0 deletions zc_install/sql/install/mysql_zencart.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2541,6 +2541,8 @@ INSERT INTO configuration (configuration_title, configuration_key, configuration
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Stock Re-order level', 'STOCK_REORDER_LEVEL', '5', 'Define when stock needs to be re-ordered', '9', '5', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Products status in Catalog when out of stock should be set to', 'SHOW_PRODUCTS_SOLD_OUT', '0', 'Show Products when out of stock<br /><br />0= set product status to OFF<br />1= leave product status ON', '9', '10', 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Show Sold Out Image in place of Add to Cart', 'SHOW_PRODUCTS_SOLD_OUT_IMAGE', '1', 'Show Sold Out Image instead of Add to Cart Button<br /><br />0= off<br />1= on', '9', '11', 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable disabled product by available date', 'ENABLE_DISABLED_UPCOMING_PRODUCT', '0', 'Enable product that had an available date entered and the current date has come to exist or pass.<br /><br />0= off<br />1= on', '9', '12', 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());


INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Product Quantity Decimals', 'QUANTITY_DECIMALS', '0', 'Allow how many decimals on Quantity<br /><br />0= off', '9', '15', 'zen_cfg_select_option(array(\'0\', \'1\', \'2\', \'3\'), ', now());

Expand Down
3 changes: 3 additions & 0 deletions zc_install/sql/updates/mysql_upgrade_zencart_157.sql
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ INSERT INTO product_type_layout (configuration_title, configuration_key, configu
INSERT INTO product_type_layout (configuration_title, configuration_key, configuration_value, configuration_description, product_type_id, sort_order, set_function, date_added) VALUES ('Show \"Ask a Question\" button?', 'SHOW_DOCUMENT_PRODUCT_INFO_ASK_A_QUESTION', '1', 'Display the \"Ask a Question\" button on product Info pages? (0 = False, 1 = True)', 4, 14, 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'), array(\'id\'=>\'0\', \'text\'=>\'False\')), ', now());
INSERT INTO product_type_layout (configuration_title, configuration_key, configuration_value, configuration_description, product_type_id, sort_order, set_function, date_added) VALUES ('Show \"Ask a Question\" button?', 'SHOW_PRODUCT_FREE_SHIPPING_INFO_ASK_A_QUESTION', '1', 'Display the \"Ask a Question\" button on product Info pages? (0 = False, 1 = True)', 5, 14, 'zen_cfg_select_drop_down(array(array(\'id\'=>\'1\', \'text\'=>\'True\'), array(\'id\'=>\'0\', \'text\'=>\'False\')), ', now());

# Add control for enabling product that were disabled and have a products_available_date that has passed in time and is not set to the Zen Cart equivalent of an ignored/empty date.
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable disabled product by available date', 'ENABLE_DISABLED_UPCOMING_PRODUCT', '0', 'Enable product that had an available date entered and the current date has come to exist or pass.<br /><br />0= off<br />1= on', '9', '12', 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
zcwilt marked this conversation as resolved.
Show resolved Hide resolved

DELETE FROM configuration WHERE configuration_key = 'ADMIN_DEMO';

#val_function update for MIN values
Expand Down