Zen Cart Logo

Hiding Categories

Views: 8,408

Results 1 to 20 of 27
28 Dec 2007, 4:56 AM
#1
ally71 avatar

ally71

New Zenner

Join Date:
Dec 2007
Posts:
9
Plugin Contributions:
0

Hiding Categories

Am new to using the software have everything set up and looking great. Just a quick question that I couldnt seem to find an answer to. Can you hide categories/ subcategories when they dont have any stock or product listed in them?
Just want to save my customers following those links until such time as I upload stock to them.
Thanks
Ally

28 Dec 2007, 5:27 AM
#2
kobra avatar

kobra

Black Belt

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

Re: Hiding Categories

Try in the admin > config > stock > Products status in Catalog when out of stock should be set to > 0= set product status to OFF

29 Dec 2007, 12:19 PM
#3
ally71 avatar

ally71

New Zenner

Join Date:
Dec 2007
Posts:
9
Plugin Contributions:
0

Re: Hiding Categories

Thanks for your help will try that :smile:

29 Dec 2007, 3:14 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Hiding Categories

Unfortunately that won't hide the category when it is empty. You can manually disable any category that doesn't have products ready for sale, in Catalog > Categories/Products. Click on the green button next to the category in the list (under Status) and it will turn red.

28 Oct 2008, 12:20 PM
#5
ceegeeaar avatar

ceegeeaar

New Zenner

Join Date:
Mar 2007
Location:
Deep in the Black Country, UK
Posts:
34
Plugin Contributions:
0

Re: Hiding Categories

Is there some sql I could paste which would disable empty categories rather than ploughing through them all manually?
I have a site populated with 16000 products in an industry standard category structure. There are unused categories which I have managed to hide in the categories sidebox using the categories dressing mod but there is a category list at the top of the page which still has them and also subcategories displayed on the main page show them so I think it would be better to disable the empty ones rather than 'not display' them - set their status to 0.
With 16000 products and 1500 categories that is a mammoth task and Im sure there is an 'automatic' way to do this with an sql statement but Im not familiar enough with sql to come up with it myself :blush:

28 Oct 2008, 3:42 PM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Hiding Categories

For a start, /includes/functions/functions_categories.php should have a function to count the products in a category. From there, you could loop through the categories and apply SQL to reset the status of each cat without products. Someone should be able to come up with the SQL statement for the resetting.

28 Oct 2008, 6:35 PM
#7
ceegeeaar avatar

ceegeeaar

New Zenner

Join Date:
Mar 2007
Location:
Deep in the Black Country, UK
Posts:
34
Plugin Contributions:
0

Re: Hiding Categories

I noticed the count is shown in the admin side aswell. It could probably be used to perform the same function as clicking the icon, without the confirmation page. Thats as far as I got before I became expertiseless tho!:wacko:

1 Jan 2009, 2:29 AM
#8
tarch avatar

tarch

New Zenner

Join Date:
Dec 2008
Posts:
1
Plugin Contributions:
0

Re: Hiding Categories

gjh42:

For a start, /includes/functions/functions_categories.php should have a function to count the products in a category. From there, you could loop through the categories and apply SQL to reset the status of each cat without products. Someone should be able to come up with the SQL statement for the resetting.

Somebody could give this SQL statement? TIA!

16 May 2009, 10:41 AM
#9
zwempha avatar

zwempha

New Zenner

Join Date:
Mar 2009
Posts:
1
Plugin Contributions:
0

Re: Hiding Categories

Sorry for the late reply, but I just found this thread when looking for the same thing. I didn't find the answer so I came up with these queries.
To hide:


To delete:


Use at own risk, dosen't work just yet.

Regards!
Sven ,Sweden
-Noob Carter-

17 Nov 2009, 12:46 AM
#10
drrogera avatar

drrogera

New Zenner

Join Date:
Aug 2009
Posts:
38
Plugin Contributions:
0

Re: Hiding Categories

Here is a query that will return a list of categories that have active products and 4 levels above that those categories are subs to - how you choose to use it is your business. In other words, if you use it to delete categories that you later find should not have been, I am not responsible.

At this stage it only handles 5 levels - but it could go farther if needed. I have tested this in MySQL and it tolerates the nested sub-selects. Using an ODBC connection I found that MS Access does not.

SELECT categories_id FROM zen_products_to_categories
WHERE products_id IN (SELECT products_id FROM zen_products WHERE products_status = 1)
UNION
SELECT zen_categories.parent_id FROM zen_categories 
WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories)
UNION
SELECT parent_id FROM zen_categories 
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories))
UNION
SELECT parent_id FROM zen_categories 
WHERE categories_id IN (SELECT parent_id FROM zen_categories 
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories)))
UNION
SELECT parent_id FROM zen_categories
WHERE categories_id IN (
SELECT parent_id FROM zen_categories 
WHERE categories_id IN (SELECT parent_id FROM zen_categories 
WHERE categories_id IN( SELECT zen_categories.parent_id FROM zen_categories WHERE zen_categories.categories_id In (SELECT categories_id FROM zen_products_to_categories))))
ORDER BY categories_id

Good luck and ALWAYS backup your database!

17 Nov 2009, 4:18 AM
#11
ajeh avatar

ajeh

Oba-san

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

Re: Hiding Categories

I am afraid you have an error in your SELECT as you are also picking up the Top Level categories_id that have subcategories in them ...

Is your intent to pick categories_id where there are active products "somewhere" within the branch or within the active products' active categories_id ...

17 Nov 2009, 7:21 AM
#12
drrogera avatar

drrogera

New Zenner

Join Date:
Aug 2009
Posts:
38
Plugin Contributions:
0

Re: Hiding Categories

Ajeh:

I am afraid you have an error in your SELECT as you are also picking up the Top Level categories_id that have subcategories in them ...

Is your intent to pick categories_id where there are active products "somewhere" within the branch or within the active products' active categories_id ...

The idea was to pickup any categories that had an active product somewhere below. So the idea was to get to the top as it were. I hope I got hat correct.

UNION queries are my favorite. When I see them I know the person has gotten deep into the guts of SQL. I never hire a DBA that cannot tell me where the Group By goes in a UNION query. So, if you know, don't write it here.:wink:

23 Nov 2010, 5:18 PM
#13
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

Has any one got the code for this? I really cant be bothered to work it out - It should be an option in zen cart anyway....

23 Nov 2010, 5:46 PM
#14
kobra avatar

kobra

Black Belt

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

Re: Hiding Categories

Has any one got the code for this?
It is in post#11
I really cant be bothered to work it out
Then take it the way it is
It should be an option in zen cart anyway....
Can not be all things for all wants
That is why it is open source

23 Nov 2010, 6:18 PM
#15
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

I wasn't looking for philosophy, i will take that as you dont know...

23 Nov 2010, 6:21 PM
#16
kobra avatar

kobra

Black Belt

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

Re: Hiding Categories

i will take that as you dont know...
post #11

23 Nov 2010, 6:30 PM
#17
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

Basicallly I ran an sql code to disable any products which didnt have images and I am now finding empty categories on the menu. So it is pointless them being there. I dont want to do it manually as I process my data from a different database so a code to disable empty categories or just hide them on the menu is all i am looking for.

It's a great idea for a menu mod or just as core code in zen cart.
I can look into it if no one else has found the solution but i would prefer it if someone has already found out and is willing to contribute this information to the open source community of zen cart....

It is quite difficult though i think because you are counting subcategory counts aswell and looking at multiple tables....

23 Nov 2010, 6:36 PM
#18
kobra avatar

kobra

Black Belt

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

Re: Hiding Categories

so a code to disable empty categories or just hide them on the menu is all i am looking for.
My BAD it is Post #10 that has sql to return cats with active items and this can be used/altered to build upon

23 Nov 2010, 6:39 PM
#19
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

Thanks I will take a closer look at that

23 Nov 2010, 8:58 PM
#20
webmc avatar

webmc

New Zenner

Join Date:
Jul 2010
Location:
Kent UK
Posts:
50
Plugin Contributions:
0

Re: Hiding Categories

I was thinking more like

return $products_count;
if ($products_count <=0){$query="update " . TABLE_CATEGORIES . " set categories_status =0 where categories_id = ".$products->fields['categories_id']."";
$query = $db->Execute($query);}

in the functions_categories.php to update the status to 0 based on category count althought this code doesnt work