Forums / Setting Up Categories, Products, Attributes / How to hide categories with no active products?

How to hide categories with no active products?

Views: 26,152

Results 41 to 60 of 83
20 Nov 2014, 1:51 PM
#41
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

How to hide categories with no active products?

mikeel100:

This does work in 1.5.3 ... please consider adding this to the next upgrade package.

If it were to be added to the codebase, it should be an admin configurable item..

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.

21 Nov 2014, 1:20 AM
#42
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'

21 Nov 2014, 2:57 AM
#43
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to hide categories with no active products?

mikeel100:

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...

21 Nov 2014, 1:54 PM
#44
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: How to hide categories with no active products?

mikeel100:

Why? What is the point of showing empty categories? There are already too many "configurable options" in the admin area...just sayin'

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.

mc12345678:

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.
nods in agreement :yes:

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.

21 Nov 2014, 2:26 PM
#45
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to hide categories with no active products?

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!]
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!

21 Nov 2014, 4:39 PM
#46
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: How to hide categories with no active products?

Ajeh:

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 ...

Awesome news Ajeh!!! and kudos for making is CHOICE for shopowners.. (not a fan of "one size fits all" features) I do have a few clients who want this (hence why I subscribed to this thread to begin with) so it will be nice to see this make it's way into the core..

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.

21 Nov 2014, 4:55 PM
#47
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to hide categories with no active products?

If you guys want to test this the changes are marked in RED:
/includes/templates/template_default/sideboxes/tpl_categories.php

    if ([B](CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && $box_categories_array[$i]['count'] == 0) ||[/B] 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)
[B]       // skip empty or status off categories
[/B]    } 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/categories_tabs.php

  // create link to top level category
[B]  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

[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/classes/site_map.php

      $categories = $db->Execute($categories_query);
      while (!$categories->EOF) {
[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]          $this->data[$categories->fields['parent_id']][$categories->fields['categories_id']] = array('name' => $categories->fields['categories_name'], 'count' => 0);
        [B]}[/B]
        $categories->MoveNext();
      }
   }
    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)$categories->fields['categories_id']) == 0) {
          // skip empty or status off categories
          continue;
        }
[/B]        $category_link = $parent_link . $category_id;
        $result .= $this->child_start_string;
        if (isset($this->data[$category_id])) {

Then add the switch to the configuration table 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());

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 ...

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!

24 Nov 2014, 1:11 AM
#48
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

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.

24 Nov 2014, 2:05 AM
#49
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: How to hide categories with no active products?

mikeel100:

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.
Not upset.. SMH However IMHO this is a place where an option makes sense.. I have clients who have business reasons why they support either option.. glad Ajeh was on the case!

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.

24 Nov 2014, 1:29 PM
#50
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to hide categories with no active products?

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 ... :smile:

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!

24 Nov 2014, 1:41 PM
#51
divavocals avatar

divavocals

Totally Zenned

Join Date:
Jan 2007
Location:
Los Angeles, California, United States
Posts:
10,011
Plugin Contributions:
3

Re: How to hide categories with no active products?

ajeh:

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 ... :smile:

exactly!!!!

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.

24 Nov 2014, 5:02 PM
#52
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How to hide categories with no active products?

Ajeh:

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 ... :smile:

And as provided the switchis currently a simple on/off, it could even be expanded to a multi-level type switch to activate each of the above modifications differently. Though with the number of locations touched I would advise against trying to consider every potentiaal combination of settings as I would aalso guess that some shouldn't be disabled without another...

Anyways, just thinking about how far a "fix" can go. Like it though seems relatively simple. :)

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

25 Nov 2014, 1:42 AM
#53
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

Made changes as instructed above.

The Categories Sidebox has no categories showing...I think a closing bracket (}) is missing somewhere but not sure. I have 100,000 products in 2300+ categories with 11 top level categories. None are showing...just the Featured, All, New, and Specials Links.

Site Map - I get a 500 server error.

The center box area categories / subcategories appear to be working.

Category Tabs (top of main page) appears to be working.

I triple checked the code to make sure it is exactly as you suggested :-)

25 Nov 2014, 2:00 AM
#54
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to hide categories with no active products?

Site Map appears to be working ... did you fix this?

If so, what was your error? :lookaroun

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!

25 Nov 2014, 2:25 AM
#55
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

The second correction to the Site Map file is using $categories_tab->field instead of $categories->field.

Changing it still didn't fix the sitemap issue.

25 Nov 2014, 2:34 AM
#56
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: How to hide categories with no active products?

Good news ... I did that right for v16 ... Bad news ... I wrote that wrong for what I posted as you discovered ... :blink:

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!

25 Nov 2014, 3:05 AM
#57
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

Ajeh:

Good news ... I did that right for v16 ... Bad news ... I wrote that wrong for what I posted as you discovered ... :blink:

I've been experimenting with the sitemap code but can't seem to get it to work. The logic seems like it is all there but apparently, I'm missing something.

I'm not really concerned with the sidebox or CatTab at this point as I have completely disabled all sideboxes and CatTabs...going for a simpler / cleaner look that is a little more user friendly on mobile devices.

So, should that second edit on the sitemap file be $categories or $categories_tab? $categories makes since to me since the query just above it is $categories.

Thanks.

To answer Ajeh's questions: Internal Server Error after waiting for about 2-3 minutes for the sitemap page to load.

25 Nov 2014, 3:11 AM
#58
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

While we are looking at the sitemap file...can you tell me why "All Products" doesn't show up on the sitemap?

30 Mar 2016, 6:01 AM
#59
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

FYI...all of Ajeh's mods mentioned above work in 1.5.5. Tested and confirmed during my upgrade.

4 Jul 2016, 6:01 PM
#60
mikeel100 avatar

mikeel100

Zen Follower

Join Date:
Sep 2012
Location:
West Jefferson, NC
Posts:
391
Plugin Contributions:
0

Re: How to hide categories with no active products?

if (CATEGORIES_PRODUCTS_INACTIVE_HIDE == 1 && zen_count_products_in_category((int)$categories->fields['categories_id']) == 0) {
//skip empty or status off categories
continue;
}

FYI...If you remove the second code change(quote above) in the includes/classes/site_map.php file, the sitemap does hide the products without any quantities.

Not sure what Ajeh was trying to accomplish with this other code...may affect something I am totally unaware of.

All of Ajeh's recommended code changes are working in 1.5.5a...sideboxes unknown since I do not use them.