Zen Cart Logo
Forums / General Questions / Categories parent_id

Categories parent_id

Locked

Views: 896

Results 1 to 8 of 8
This thread is locked. New replies are disabled.
1 Apr 2009, 9:05 AM
#1
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Categories parent_id

I'm working to build a function related to categories and I've a doubt.

If the master category is 'MASTER'
the subcategory is 'SUB'
the subsubcategory i 'SUBSUB':

the parent_id of MASTER is 0
the parent_id of SUB is the categories_id of MASTER
the parent_id of SUBSUB is the categories_id of SUB

is this correct?

Also, the master_categories_id of a product of SUBSUB is the categories_id of SUBSUB or of MASTER?

Many thanks - Giovanni

1 Apr 2009, 9:40 AM
#2
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Categories parent_id

No this isn't quite correct. It would be if there is only one level of categories. But it's not generally so.

The master category is product-specific. Each product has one but they can be different.

If a product is in a top level category then its master category's parent ID would indeed be zero (which really means doesn't have a parent). But if the product has master category 2 which is a subcategory of category 1, then the parent ID of of the master category would be 1 and not 0.

This is further complicated by linked products, which allow a product to be in two or more categories at the same time. However, a product can only have one master category.

I'm guessing that you may have more questions about this ... please feel free to ask them. :smartalec:

2 Apr 2009, 4:59 AM
#3
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Re: Categories parent_id

well, kuroy
I want to make some controls on categories, sub-categories and sub-sub-categories. For this I've modified the database and built a function for the control.

In the category and subcategory I can control the situation. In includes\modules\mytemplate\category_row.php I've modified the code at row 31

while (!$categories->EOF) {

$cat_num = $categories->fields['categories_id'];
$cat_vis = zen_control_categories_visibility ($cat_num);
if (!$cat_vis) $categories->MoveNext();

if (!$categories->fields['categories_image']..........

The 3 statements that I've added (also in other scripts) works well for te categories and the sub-categories, but don't work for the sub-sub-categories and I'm not able to find where modify something!
For this I've theese doubts!
Any idea about the script to modify??

Thanks - Giovanni

2 Apr 2009, 5:32 AM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Categories parent_id

Since zen_control_categories_visibility () is a custom function, it might help to see its code. The code you posted seems so straightforward that it is hard to imagine it being the source of the problem. What is the problem, anyway? This is apparently supposed to hide particular categories in certain circumstances??

2 Apr 2009, 5:42 AM
#5
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Re: Categories parent_id

Yes.....
I've added a field to the categories table to control the visibility (for resellers).
the problem is that I'm not able to control the sub-sub-catebories when there's shown in the main page (clicking the sub-categories on the category box).
In all the other situation the control is right.
If you like I can post the function, but is not there the problem.
Any idea???? - Thanks - Giovanni

2 Apr 2009, 5:44 AM
#6
gjh42 avatar

gjh42

Black Belt

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

Re: Categories parent_id

You may be confusing the code in this while loop.
Perhaps instead of

if (!$cat_vis) $categories->MoveNext();

you should wrap the conditional around the rest of the while content so it skips to the MoveNext at the bottom:

if ($cat_vis) {
if (!$categories->fields['categories_image']..........
...
}
$categories->MoveNext();

I don't know if this is related to your problem, but it seems like it could cause some kind of misbehavior.

2 Apr 2009, 6:03 AM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Categories parent_id

I've figured out what was bugging me about that code:
You have a while loop that is supposed to stop at the last category in the array, but you will increment the count twice when you skip a category. If it was processing the last category in the array and skips it, it will proceed to try to process the last + 1, which doesn't exist.
This may not cause a fatal error, but it sounds like it could cause some incorrect output.

2 Apr 2009, 7:27 AM
#8
g_nencini avatar

g_nencini

Zen Follower

Join Date:
Mar 2006
Location:
Florence, Italy
Posts:
153
Plugin Contributions:
0

Re: Categories parent_id

Many thanks, gjh42
this was the problem, and is happened because perhaps I'm too tired!!!
Now all is going perfectly - Many thanks again - Giovanni