Get the categories in order.

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
robgrigg
Lieutenant (LT)
Lieutenant (LT)
Posts: 76
Joined: Fri Jun 12, 2009 2:22 am

Get the categories in order.

Post by robgrigg » Mon May 24, 2010 10:51 am

Hi,

I am currently using the

Code: Select all

CategoryCollection categories = CategoryDataSource.LoadForParent(categoryId, true);
methos to get the root category and then recurse on this to build a menu.

All is fine except I have just noticed that the categories are ordered as they wre created. not as they are organised in the admin screen.
In fact, changing the order in admion has no effect.

Can you tell me how I get the root category and the any other category by categoryId whilst preserving the order set in admin and also only including active categories.

Thanks.

R.

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Get the categories in order.

Post by mazhar » Mon May 24, 2010 12:02 pm

I guess LoadForParent doesn't support sort expression ability. Give a try to load categories as below

Code: Select all

CatalogNodeCollection categoryNodes = CatalogNodeDataSource.LoadForCategory(categoryId, "OrderBy ASC");
        CategoryCollection categories = new CategoryCollection();
        foreach (CatalogNode catalogNode in catalogNodes)
        {
            if (catalogNode.CatalogNodeType == CatalogNodeType.Category)
                categories.Add((Category)catalogNode.ChildObject);
        }

Post Reply