My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.
Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'
The absence of a product in a category doesn't mean that the category (and with modification all of the parent categories) is useless or doesn't provide value for the store. While generally not suggested to have a "coming soon" type display of information, I'm sure that over the years that store owners have found creative ways to use categories that do not have products for various things. As well, as pointed out the offered code only addresses the last category not having products. It doesn't address all categories between the top and that last categoy. Not that it couldn't be modified to do so, but even that additional code would be recommended to be an admin configurable option.
ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...
Because just because YOU don't want to show empty categories doesn't mean that ALL STORES should be FORCED to have the SAME option because YOU don't agree with or understand it.. (hence WHY it should be an admin configurable option). Plus as mc12345678 pointed out this isn't a complete solution to cover ALL variables of hiding empty categories..
As for WHY would you want empty categories??? There are MANY business reasons for this and I am NOT going to list them all and do the follow-up "back and forth" discussion on them and take this thread WAAAAAY off topic.. You may think there are too many admin options, but that simply makes Zen Cart FLEXIBLE and not some silly "one size fits all" solution. Additionally CHOICES for these options keeps novices from making core code changes they may not remember they made when upgrading their site.. Frankly I'm glad Zen Cart offers configuration options that allow you more than ONE option where it's CLEAR there should be choices.. Otherwise this forum will be filled even more with those "how can I do this?" posts.
**nods in agreement**![]()
Last edited by DivaVocals; 21 Nov 2014 at 02:57 PM.
My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.
This is being worked into v16 as v154 is close to release and this cannot be added ...
There are 4 files that should be addressed:
/includes/templates/template_default/sideboxes/tpl_categories.php
/includes/modules/category_row.php
/includes/modules/categories_tabs.php
/includes/classes/site_map.php
to manage hiding the categories when either they are empty or when they only contain Products with products_status = 0 ...
This would be controlled by an on/off switch in the Admin to allow for those who want this feature and those who do not ...
When I have time, I will try to post the changes needed but I need to compare them to v154 vs v151 to see what the differences, if any, may be ...
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: v1.5.5]
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!
My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.
If you guys want to test this the changes are marked in RED:
/includes/templates/template_default/sideboxes/tpl_categories.php
/includes/modules/categories_tabs.phpCode: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 } else { $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">'; if ($box_categories_array[$i]['current']) { if ($box_categories_array[$i]['has_sub_cat']) {
/includes/modules/category_row.phpCode:// create link to top level category 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/classes/site_map.phpCode: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();
Code:$categories = $db->Execute($categories_query); while (!$categories->EOF) { if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) { // skip empty or status off categories } else { $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0); } $categories->MoveNext(); } }Then add the switch to the configuration table via the Tools ... Install SQL Patches ...Code: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)$categories->fields['categories_id']) == 0) { // skip empty or status off categories continue; } $category_link = $parent_link . $category_id; $result .= $this->child_start_string; if (isset($this->data[$category_id])) {
Setting this new setting in the Configuration ... Layout Settings ... for Categories with Inactive Products Status to 0 or OFF will NOT hide the empty Categories or Categories with all Products set to products_status = 0 and setting this to 1 or ON will hide them ...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());
Last edited by Ajeh; 25 Nov 2014 at 03:37 AM. Reason: FIX TYPO
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: v1.5.5]
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!
It was a legitimate question...not intended to upset anyone. (DivaVocals)
I still do not see the point of showing categories when no active products are available. It is like having an empty cookie jar on the counter...very frustrating to open it up and see nothing in it when you were expecting to.
I was not implying that this be a ONE SIZE FITS ALL program...but I have been programming long enough to know that you can option yourself to death if you are not careful.
I fully appreciate the flexibility of this outstanding program and the people who make it possible! That is why I have followed this program steadily since 1.3.7.
Thanks for the code Ajeh and for appeasing everyone! You have been a tremendous help indoctrinating me into this program. Novice...maybe, but at least I am looking for ways to improve.
My Site - Zen Cart & WordPress integration specialist
I don't answer support questions via PM. Post add-on support questions in the support thread. The question & the answer will benefit others with similar issues.
You guys are welcome ...
While I would consider the loss of spiders not finding the Category when disabled and good Category description can help get the Products spidered ... I can also see the desire for this feature ...
But, to each their own, hence the switch ...![]()
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: v1.5.5]
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!
Bookmarks