Hi,
You have this method:
Dynamicweb.Ecommerce.Products.Group.GetAllGroups();
How would one go about getting groups in sorted fashion? Like the menu would output it.
//jan
Developer forum
E-mail notifications
Get groups sorted via API - Ecom
Replies
Hi Jan
Groups are a many-to-many relation where the same group can have more than one parent and each of those relationships has its own sort value. Those values can be found in EcomGroupRelations table in the database.
Therefore you need some kind of tree context in order to sort the groups.
If you have a Group object, you can simply ask for Subgroups property - which is sorted.
Alternatively you can use the ParentGroupSortOrderComparer to sort a collection. But it would be the same thing...
Dim relationsByParent As GroupRelationCollection = GroupRelation.GroupRelationsByParentId(parentId)
CType(Items, List(Of Group)).Sort(New ParentGroupSortOrderComparer(parentId, relationsByParent))
BR Nicolai
Hi Nikolai,
I get the subgroups are sorted. But how would one get the topgroups sorted via API then?
Any easy method there or?
I tried simply putting 0 in as "parentid" - but no luck. Perhaps I am just missing the correct format for the parentid for topgroups?
Hi Jan,
You can get the top level groups from the shop.
Try something like this...
var shopId = Dynamicweb.Frontend.PageView.Current().Area.EcomShopId; var shop = !string.IsNullOrEmpty(shopId) ? Dynamicweb.Ecommerce.Services.Shops.GetShop(shopId) : Dynamicweb.Ecommerce.Services.Shops.GetDefaultShop(); if (shop != null) { var topLevelGroups = shop.TopLevelGroups; foreach (var topLevelGroup in topLevelGroups) { var subGroups = topLevelGroup.Subgroups; } }
Best regards,
Morten
Perfect Morten.
I have it sorted now:>
You must be logged in to post in the forum