Forums / Setting Up Categories, Products, Attributes / Don't show category when it has no products

Don't show category when it has no products

Locked

Views: 3,575

Results 1 to 20 of 20
This thread is locked. New replies are disabled.
1 Mar 2007, 11:02 AM
#1
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Don't show category when it has no products

Hi all.

How can I do the above please? I don't want a category showing if there's nothing in it.

Once again, I've tried to search for this answer but as usual the search throws up hundreds of threads :(

p.s - I'm sure this was an option on oS Commerce.

Cheers

1 Mar 2007, 3:16 PM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Don't show category when it has no products

In the admin where the categories are displayed there is a green square/button and clicking this changes it to red and disables it.....Is this what you are seeking??

Zen-Venom Get Bitten

1 Mar 2007, 4:06 PM
#3
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Not really, I want it to be automatic.

In other words, a bit of code that says:

"Does this category have any products, if 'no', then don't display it"

I'll do what you suggest as a workaround.

Ta.

1 Mar 2007, 4:36 PM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Don't show category when it has no products

"Does this category have any products, if 'no', then don't display it"Do you mean no products or no products with stock?

Zen-Venom Get Bitten

1 Mar 2007, 5:48 PM
#5
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Good question.

I mean 'No Products'

I don't mind the odd 'sold out' here and there :-)

1 Mar 2007, 6:39 PM
#6
tvadpro avatar

tvadpro

Zen Follower

Join Date:
Aug 2005
Location:
Cincinnati
Posts:
323
Plugin Contributions:
0

Re: Don't show category when it has no products

Admin/Configuration/Layout Settings: Categories with 0 Products Status = 0

budfox:

Good question.

I mean 'No Products'

I don't mind the odd 'sold out' here and there :-)

1 Mar 2007, 8:16 PM
#7
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Thanks, but that isn't it.

That option puts a (0) after each category that has no products.

I'm hoping to not see the category at all. The idea being that the store doesn't look so empty when we don't have much to sell.

1 Mar 2007, 9:55 PM
#8
tvadpro avatar

tvadpro

Zen Follower

Join Date:
Aug 2005
Location:
Cincinnati
Posts:
323
Plugin Contributions:
0

Re: Don't show category when it has no products

Wow -- you're right! All this time I thought that one disabled category display when the category had no products ...> budfox:

Thanks, but that isn't it.

That option puts a (0) after each category that has no products.

I'm hoping to not see the category at all. The idea being that the store doesn't look so empty when we don't have much to sell.

1 Mar 2007, 9:59 PM
#9
tvadpro avatar

tvadpro

Zen Follower

Join Date:
Aug 2005
Location:
Cincinnati
Posts:
323
Plugin Contributions:
0

Re: Don't show category when it has no products

Maybe there was never any call for such a control. I've always just disabled empty categories manually in Categories/Products by clicking the green status button so it turns red.

1 Mar 2007, 10:12 PM
#10
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Are we able to put in a request then, or perhaps someone PHP literate could write a mod in 10 seconds....

1 Mar 2007, 10:43 PM
#11
tvadpro avatar

tvadpro

Zen Follower

Join Date:
Aug 2005
Location:
Cincinnati
Posts:
323
Plugin Contributions:
0

Re: Don't show category when it has no products

This could be my PHP illiteracy talking (I'm in awe of programmers), but I think 10 seconds may require someone who is PHP-omnipotent.

However, what you describe sounds like something that would require little more than a conditional statement wrapped around a portion of the catalog sidebox template or module. Shouldn't be too hard to find someone to do that, possibly if you ask around in the Customizing forum.> budfox:

Are we able to put in a request then, or perhaps someone PHP literate could write a mod in 10 seconds....

1 Mar 2007, 10:56 PM
#12
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Thankyou.

It's something my client might ask for, so I'll ask on the custom forum for a price quote.

Then everyone else can use the mod if they wish.

2 Mar 2007, 5:43 PM
#13
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Don't show category when it has no products

When I asked - Do you mean no products or no products with stock?
You responded:
Good question.

I mean 'No Products'
I am confused??? Why set up a category "only" if you are not going to place product in it???

If setting it up for future use - just click the "green" button to disable it until you add product to it.

Zen-Venom Get Bitten

2 Mar 2007, 5:53 PM
#14
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Don't show category when it has no products

I have to agree.

If your client is going to be adding any new products (and learn how to do it), disabling an empty category is trivially easy.

If they are not adding products, then the one who is can disable the category.

Unlike in/out of stock, this is not something that will change often, only when the first product is added or the last one is deleted from a category.

2 Mar 2007, 6:09 PM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Don't show category when it has no products

If you want the catalog permanently set so empty categories are hidden, that should be easy. Layout Settings: "Categories with 0 Products Status = 0" indicates that the code gets the info already and uses it to show the count or not. This code could be applied to the whole category being displayed.

Putting a new switch in admin would be considerably more involved.

Hmmm... I bet the switch above when modified would function to turn off cat display instead of just turn off count display...

2 Mar 2007, 6:28 PM
#16
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Thanks for the interest.

Here's the deal. At https://www.wheredidyougetit.co.uk/shop we will nearly always have the same categories. It is very unlikely that they will change.

We don't mind some cateogires with products sold out, and at some point we will delete those products if we aren't likely to get anymore. We do feel that a few 'sold outs' isn't a bad thing.

What we don't want though is categories with no products. That gives the impression of a store that doesn't have much stock, rather than in the above case which gives the impression of a store selling a good few things.

I fully accept that enabling/disabling the category is easy, but it isn't as easy as if it happened automagically. That also means we won't forget to enable/disable as appropriate.

I don't need a new setting in admin, just a hard coded solution for which we will be willing to pay once we've actually made a few sales.

Thanks all.

Steve

3 Mar 2007, 6:29 PM
#17
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Don't show category when it has no products

Looking at this... I have found a solution that works if category counts are on.

In /includes/templates/your_template/sideboxes/tpl_categories.php,

$box_categories_array[$i]['count'] == 0

functions in about line 50 to control display of counts.

         if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
 

In about line 31, add

$box_categories_array[$i]['count'] != 0 or

to get:

     if ($box_categories_array[$i]['count'] != 0 or 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) 

This only works if category counts are displayed(turned on in Configuration > My Store). "Categories with 0 Products Status" makes no difference.

If counts are turned off, $box_categories_array[$i]['count'] is always == 0 and can't be used for anything. This makes sense because a main point of turning it off is to save on db queries. Probably the only other way to have that info would be to query for the category and all of its subcats having no products_to_categories links (that part of the table empty).

3 Mar 2007, 9:10 PM
#18
budfox avatar

budfox

Zen Follower

Join Date:
Aug 2006
Posts:
88
Plugin Contributions:
0

Re: Don't show category when it has no products

Thankyou for your time.

That looks good to me, and I'd like to think that one day I'd have been clever enough to work it out for myself.

20 Feb 2009, 10:09 PM
#19
zandergraphics avatar

zandergraphics

New Zenner

Join Date:
Feb 2009
Posts:
5
Plugin Contributions:
0

Re: Don't show category when it has no products

gjh42:

Looking at this... I have found a solution that works if category counts are on.

...

In about line 31, add

$box_categories_array[$i]['count'] != 0 or

to get:

 if ($box_categories_array[$i]['count'] != 0 or 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) 

Tried the above and couldn't get it to work until I used:

```php
if ($box_categories_array[$i]['count'] < 1 or 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)) {

It all comes together, one piece at a time, as always....

21 Feb 2009, 5:44 AM
#20
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Don't show category when it has no products

Yes, that's right... :oops: the test is for conditions to disable the category, so we want to see if the "empty" trigger is true.
$box_categories_array[$i]['count'] == 0
or
$box_categories_array[$i]['count'] < 1
should both work correctly.