The first sortOrder (of HatX) is in NodeEntryRelation table, while the sortOrder of nodes (Hats/Accessories) are in CatalogNode table. To get those, you can use the CatalogNode Id/Code to get the CatalogNodeDto/CatalogNode entities, then get the SortOrder.
Here is my suggestion:
Add an overload to GetNodeRelations method that would give you the all parent nodes and their sort order:
var nodeRelations = currentContent.GetNodeRelations(includeParents:true);
Ideally this should work from both catalog entry and catalog node objects.
My apologies. I must be drunk today. The SortOrder of Node relation has been implemented by Relation (and NodeRelation, as it inherits from Relation). You should be able to use GetRelationsBySource(Hats.ContentLink) to get all relation when Hats is a child, then you can get SortOrder from it.
That is the thing, GetRelationsBySource gives me 0 hits for node content (Hats) and only the first parent for catalog entry content (HatX).
You're using one of those:
var relations = accessoriesNode.GetNodeRelations();
var links_a = LinksRepository.GetRelationsByTarget(parentNode.ParentLink);
var links_b = LinksRepository.GetRelationsBySource(accessoriesNode.ContentLink);
Here is my code (currentStyle is catalog entry object, type ProductContent).
// finding node relation for current catalog entry var nodeRelation = currentStyle.GetNodeRelations().First(); var parentNode = ContentLoader.Get
(nodeRelation.Target); _sortOrderByNode.Add(parentNode.Code, nodeRelation.SortOrder); // finding all relations for catalog node var relations = LinksRepository.GetRelationsBySource(parentNode.ContentLink).ToList();
relations is giving me 0 hits for parentNode Hats.
Hmm. For me it's a bug. GetRelationsBySource only get "linked" catalog nodes, except direct parent node. I'll file a bug for this case.
Thank you. In the meanwhile you can still use my suggested method to get the sort order.
@Quan: Do you know if this has been fixed in the latest package updates?
No, it's still in active stage. We have some higher priority works so this got lower in the queue.
The bug was closed "As designed". However, we tend to do an relation overhaul in next major version of Commerce, as in this story http://world.episerver.com/support/Bug-list/bug/CMS-1544
I don't think you can access the link right now as it's still in a draft, but want to keep it here for future reference.
Lets say I have the following catalog structure:
I want to find all nodes "HatX" belongs to and what the sort order for that node is.
Starting from "HatX" I can retrive the "Hats" node and the sort order like this:
Now parentNode will be of type ChannelNode and represent "Hats". I can navigate to "Accessories" by using parentNode.parentLink, but how can I retrieve the sort order? All of the methods below is giving me 0 hits: