CateogryParents

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

CateogryParents

Post by heinscott » Fri May 23, 2008 11:58 am

Quick Question...
Does anyone know of a quick way to recreate the CategoryParents table? I have all my Category, and CatalogNode entries correct, but, don't really want to write code to recreate the parents table...
Any ideas?
Thanks

Scott

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: CateogryParents

Post by Logan Rhodehamel » Fri May 23, 2008 2:02 pm

You might be able to make a script that loops through your categories and uses the category.SetParent method to generate the required table entries. But you would have to process them in order of level (top level first, then sub, then sub sub) otherwise the setparent method won't work right.

EDIT: That might be Category.UpdateParent.
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

User avatar
Logan Rhodehamel
Developer
Developer
Posts: 4116
Joined: Wed Dec 10, 2003 5:26 pm

Re: CateogryParents

Post by Logan Rhodehamel » Fri May 23, 2008 2:03 pm

Also there is an explanation of what data goes into that parent table here: http://wiki.ablecommerce.com/index.php/ ... Categories
Cheers,
Logan
Image.com

If I do not respond to an unsolicited private message, it's not because I'm ignoring you. It's because the answer to your question is valuable to others. Try the new topic button.

User avatar
heinscott
Captain (CAPT)
Captain (CAPT)
Posts: 375
Joined: Thu May 01, 2008 12:37 pm

Re: CateogryParents

Post by heinscott » Fri May 23, 2008 2:55 pm

Logan... Thank you SO much for the prompt reply. That Category.UpdateParent was the thing I needed... After that, it's just a simple recursion problem.
Here's the script I came up with, in case it is useful to anyone... It finds the leaf categories first, and then updates backwards, to make sure updates occur in proper sequence.

protected void buildGrid()
{
SetParents(0);
}

protected void SetParents(int ChildID)
{
CategoryCollection c = CategoryDataSource.LoadForParent(ChildID, true);
if (c.Count != 0)
{
foreach (Category cat in c)
{
SetParents(cat.CategoryId);
Category.UpdateParent(cat.CategoryId, cat.ParentId);
}
}
else
{
Category cc = CategoryDataSource.Load(ChildID);
Category.UpdateParent(cc.CategoryId, cc.ParentId);
}
}

Thanks again, Logan.

Scott

notsop
Ensign (ENS)
Ensign (ENS)
Posts: 18
Joined: Thu Apr 09, 2015 3:51 am

Re: CateogryParents

Post by notsop » Thu May 14, 2015 7:49 am

I know this is an old topic, but how would I run the script to upate the CategoryParents table?

Thanks for the help.

Chandler

Post Reply