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?tessthepup wrote: ↑Sun Jan 08, 2023 6:54 pmThanks @ecartz However now all categories are hidden whether they are status of 1 or 0
Hide Categories with no products / turn categories off
-
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
- 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
@ecartz Apologies for not getting back sooner as had major laptop failure and had to transfer everything to replacement.LeeFoster wrote: ↑Tue Jan 10, 2023 11:35 amDid 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?tessthepup wrote: ↑Sun Jan 08, 2023 6:54 pmThanks @ecartz However now all categories are hidden whether they are status of 1 or 0
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.
- burt
- Core Team
- Posts: 4556
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Hide Categories with no products / turn categories off
Matts code sort very nearly is there.
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.
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.
I am here to build with you. Let's help each other.
- burt
- Core Team
- Posts: 4556
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Hide Categories with no products / turn categories off
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.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.
I am not here to build for you.
I am here to build with you. Let's help each other.
I am here to build with you. Let's help each other.
- 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
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.burt wrote: ↑Sat Jan 21, 2023 2:22 pmIf 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.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.
- burt
- Core Team
- Posts: 4556
- Joined: Tue Oct 29, 2019 9:37 am
- Phoenix Version: v1.1.0.8
- : Buy Me A Beverage
- Has thanked: 252 times
- Been thanked: 412 times
Re: Hide Categories with no products / turn categories off
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.
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.
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
Hi,
Kind regards
Christoph
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.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.
Kind regards
Christoph