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
// create link to top level category
[B] // 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 {
[/B] $links_list[] = '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, 'cPath=' . (int)$categories_tab->fields['categories_id']) . '">' . $categories_tab_current . '</a> ';
[B] }[/B]
$categories_tab->MoveNext();
}
/includes/modules/category_row.php
// $categories->fields['products_name'] = zen_get_products_name($categories->fields['products_id']);
[B] if ((CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
// skip empty or status off categories
} else {
[/B] $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 ++;
}
[B]}[/B]
$categories->MoveNext();
}
}
/includes/templates/template_default/sideboxes/tpl_categories.php
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
for ($i=0;$i<sizeof($box_categories_array);$i++) {
[B] 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;
}
[/B] 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
$categories = $db->Execute($categories_query);
while (!$categories->EOF) {
[B] // skip empty or status off categories
if (!(CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0)) {
[/B] $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
[B] }
[/B] $categories->MoveNext();
}
}
And just a little below that:
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) {
[B] if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$category_id) == 0) {
// skip empty or status off categories
continue;
}
[/B] $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:
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
Linda McGrath
If you have to think ... you haven't been zenned ...
**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!