To have Categories automatically disappear when Products are set to products_status = 0 in Zen Cart v1.5.4, use the templates and overrides directory for the following files with the code marked in RED:
/includes/modules/categories_tabs.php
Code:
// create link to top level category
// skip empty or status off categories
if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories_tab->fields['categories_id']) == 0)) {
// skip empty or status off categories
} else {
$links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
}
$categories_tab->MoveNext();
}
/includes/modules/category_row.php
Code:
// $categories->fields['products_name'] = zen_get_products_name($categories->fields['products_id']);
if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
// skip empty or status off categories
} else {
$list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>');
$col ++;
if ($col > (MAX_DISPLAY_CATEGORIES_PER_ROW -1)) {
$col = 0;
$row ++;
}
}
$categories->MoveNext();
}
}
/includes/templates/template_default/sideboxes/tpl_categories.php
Code:
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
for ($i=0;$i<sizeof($box_categories_array);$i++) {
if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && $box_categories_array[$i]['count'] == 0) || zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
// skip if this is for the document box (==3)
// skip empty or status off categories
continue;
}
switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
/includes/classes/site_map.php
Code:
$categories = $db->Execute($categories_query);
while (!$categories->EOF) {
// skip empty or status off categories
if (!(CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
$this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
}
$categories->MoveNext();
}
}
And just a little below that:
Code:
function buildBranch($parent_id, $level = 0, $parent_link = '') {
$result = $this->parent_group_start_string;
if (isset($this->data[$parent_id])) {
foreach ($this->data[$parent_id] as $category_id => $category) {
if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$category_id) == 0) {
// skip empty or status off categories
continue;
}
$category_link = $parent_link . $category_id;
$result .= $this->child_start_string;
And to control this setting add to the database via the Tools ... Install SQL Patches:
Code:
INSERT INTO configuration (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Categories with Inactive Products Status', 'CATEGORIES_PRODUCTS_INACTIVE_HIDE', '0', 'Hide Categories with Inactive Products?<br />0= off<br />1= on', 19, 30, 'zen_cfg_select_option(array(\'0\', \'1\'), ', now());
This setting then will be found in the Configuration ... Layout Settings ...
Categories with Inactive Products Status
Hide Categories with Inactive Products?
0= off
1= on
Bookmarks