Hide Categories with no products / turn categories off

Open to all! Ask other shopowners for help.
LeeFoster
Contributor
Posts: 263
Joined: Sun Feb 28, 2021 9:41 pm
Phoenix Version: v1.0.8.20
Has thanked: 1 time
Been thanked: 5 times

Re: Hide Categories with no products / turn categories off

Post by LeeFoster »

tessthepup wrote: Sun Jan 08, 2023 6:54 pm
ecartz wrote: Sun Jan 08, 2023 6:45 pm
Omar_one wrote: Sun Jan 08, 2023 4:15 pm I think there is missing $
Yes, that is correct. It also should be referencing the class rather than the object. I updated the code in my previous post. Thanks for the reminder.
Thanks @ecartz However now all categories are hidden whether they are status of 1 or 0
Did you manage to get this working? Also how are you managing the status in the admin section or are you setting it in the database directly?


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Hide Categories with no products / turn categories off

Post by tessthepup »

LeeFoster wrote: Tue Jan 10, 2023 11:35 am
tessthepup wrote: Sun Jan 08, 2023 6:54 pm
ecartz wrote: Sun Jan 08, 2023 6:45 pm

Yes, that is correct. It also should be referencing the class rather than the object. I updated the code in my previous post. Thanks for the reminder.
Thanks @ecartz However now all categories are hidden whether they are status of 1 or 0
Did you manage to get this working? Also how are you managing the status in the admin section or are you setting it in the database directly?
@ecartz Apologies for not getting back sooner as had major laptop failure and had to transfer everything to replacement.

I tested the updated code and as you can see from the attached image it has hidden the top level categories but it has also hidden all sub categories even those with products also it has hidden the name of the category but still left a line in the menu that can be hovered over.
You do not have the required permissions to view the files attached to this post.
User avatar
burt
Core Team
Posts: 4556
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Hide Categories with no products / turn categories off

Post by burt »

Matts code sort very nearly is there.
Noname1.jpg
Here I have set the max nesting in the catgory box to 2, and disabled the Apples & Pears category.
The gap there is where the disabled category would normally show.

If Matt could solve this, it would be excellent. I can't see why it is not working.

The other thing I tried (instead of Matts idea of removing disabled cats from the category_tree output) is overriding the category_tree class to add in the c.categories_status = 1, this works perfectly in the shop side, but breaks the admin catalog.php when trying to edit a disabled category, due to the edit/delete buttons not picking up the $cPath variable. So that's a no go.
You do not have the required permissions to view the files attached to this post.
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
burt
Core Team
Posts: 4556
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Hide Categories with no products / turn categories off

Post by burt »

tessthepup wrote: Tue Jan 10, 2023 6:49 pm it has hidden the top level categories but it has also hidden all sub categories even those with products also it has hidden the name of the category but still left a line in the menu that can be hovered over.
If you hide a category, that would also hide any subcategories within it, as there is no way to get to those subcategories. Even if you made a direct link to one of those subcats, the breadcrumb would most likely fail as it would not get the data for the hidden parent category.
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Hide Categories with no products / turn categories off

Post by tessthepup »

burt wrote: Sat Jan 21, 2023 2:22 pm
tessthepup wrote: Tue Jan 10, 2023 6:49 pm it has hidden the top level categories but it has also hidden all sub categories even those with products also it has hidden the name of the category but still left a line in the menu that can be hovered over.
If you hide a category, that would also hide any subcategories within it, as there is no way to get to those subcategories. Even if you made a direct link to one of those subcats, the breadcrumb would most likely fail as it would not get the data for the hidden parent category.
I suppose the best way to do it would be have it working just like turning a product on or off so you could then turn off any sub categories and still show a top level category.
User avatar
burt
Core Team
Posts: 4556
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Hide Categories with no products / turn categories off

Post by burt »

I did code up a little hook for a "disable / enable" category for the admin side, that was fairly straightforward. Even so, if shopowner was to turn off a category that has subcats, there would be no way (in the shop side) to get to that subcat without the shop erroring out somewhere.

So long as shopowner has a system of subcategories where they only turn off categories that are at the end of a branch, it would work well. Otherwise it would take a lot of core code changes which obviously isn't ideal and isn't something that I'd want to get into as it's too much work.

Ping Matt to see if he'd take another look at that hook he provided above. If between you, can get that to remove the unwanted gaps, I'll clean up the admin hook I made and together they *might* be useful in some situations to some shopowners.
I am not here to build for you.
I am here to build with you. Let's help each other.
beerbee
Member
Posts: 48
Joined: Mon Oct 26, 2020 4:56 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 5 times

Re: Hide Categories with no products / turn categories off

Post by beerbee »

Hi,
The other thing I tried (instead of Matts idea of removing disabled cats from the category_tree output) is overriding the category_tree class to add in the c.categories_status = 1, this works perfectly in the shop side, but breaks the admin catalog.php when trying to edit a disabled category, due to the edit/delete buttons not picking up the $cPath variable. So that's a no go.
I went that way, what i did was to add the condition (still on 1.8.0 btw.) if (isset($_SESSION['admin'])) to add an extra $categories_query for logged in admins not excluding c.categories_status = 0.

Kind regards
Christoph


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply