Sort order for catalog nodes

Vote:
 

Lets say I have the following catalog structure:

Men (Node)
   Accessories (Node)
      Hats (Node)
         HatX (Product)

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:

var nodeRelation = currentContent.GetNodeRelations().First();

var parentNode = ContentLoader.Get(nodeRelation.Target);
_sortOrderByNode.Add(parentNode.Code, nodeRelation.SortOrder);

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:

var relations = accessoriesNode.GetNodeRelations();

var links_a = LinksRepository.GetRelationsByTarget(parentNode.ParentLink);

var links_b = LinksRepository.GetRelationsBySource(accessoriesNode.ContentLink);
#88822
Jul 31, 2014 14:07
Vote:
 

Hi,

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.

Regards.

/Q

#88834
Edited, Aug 01, 2014 5:22
Vote:
 

Ah, bummer. Do you know when it will be? 

#88836
Aug 01, 2014 8:01
Vote:
 

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.

#88838
Aug 01, 2014 8:29
Vote:
 

Yes, that would be even better. 

#88840
Aug 01, 2014 8:42
Vote:
 

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.

Regards.

/Q

#88841
Aug 01, 2014 8:44
Vote:
 

That is the thing, GetRelationsBySource gives me 0 hits for node content (Hats) and only the first parent for catalog entry content (HatX).

#88842
Aug 01, 2014 9:00
Vote:
 

You're using one of those:

var relations = accessoriesNode.GetNodeRelations();
 
var links_a = LinksRepository.GetRelationsByTarget(parentNode.ParentLink);
 
var links_b = LinksRepository.GetRelationsBySource(accessoriesNode.ContentLink);
But you should use. parentNode is supposed to Hats
LinksRepository.GetRelationsBySource(parentNode.ContentLink);
#88847
Aug 01, 2014 9:44
Vote:
 

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.

#88848
Aug 01, 2014 9:54
Vote:
 

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.

Regards.

/Q

#88864
Aug 01, 2014 11:53
Vote:
 

Ok, thanks Quan.

#88886
Aug 01, 2014 13:54
Vote:
 

@Quan: Do you know if this has been fixed in the latest package updates?

#90419
Sep 09, 2014 12:49
Vote:
 

No, it's still in active stage. We have some higher priority works so this got lower in the queue.

.Q

#90424
Sep 09, 2014 13:39
Vote:
 

Pinging @Quan - what is the status on this one?

#154897
Sep 01, 2016 10:25
Vote:
 

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.

/Q

#154900
Sep 01, 2016 11:05