Catalog Node childs Episerver v11



How can i get all node childes and their childs including childs from CatalogNodeRelation table from  Mediachase.Commerce.Catalog.Dto.CatalogNodeDto object?

And theirs entities as additional question.

so for examaple i have node "All products" and as the result i want to get ["Node", "61309895","61311000", "6135198"]

Thanks in advanced.

Edited, Sep 12, 2017 12:08

You can use IRelationRepository, and then GetChildren<NodeRelation>(yourNodeLink) to get the references of the children (nodes and entries).

I could not see your picture so I guess that's what you want. To get the code from ContentReference, you can use ReferenceConverter.

Sep 12, 2017 12:45

Quan Mai,

thanks for answer, but I think that convert CatalogNodeDto  to ContentReferences and then use ReferenceConverter to get Code is not afficient. But more than that i need to do it in a loop to get chil of child.

My imput has type CatalogNodeDto. I have attach image one more time. 


Edited, Sep 12, 2017 12:54

Still can't see it. But if you already have the ChildNodeId, you can use ReferenceConverter to get the contentLink (.GetNodeLink()), and then use that to get the code. 

Edited, Sep 12, 2017 13:01

I hope you can see the picture now.

I want to get all nodes (subtree where relation between nodes can be denifined in [CatalogNodeRelation] and [CatalogNode] table) from "All Products" In one function if there are so, without converting CatalogNodeDto to ContentLink back and forth, and the most Important here is to account CatalogNodeRelation table.

so for examaple i have node "All products" and as the result i want to get ["Node", "61309895","61311000", "6135198"] .

Is there good solution for this?

Sep 12, 2017 13:40

I would actually use the IContentLoader.GetChildren for this. Quan, won't you miss out getting the Node (Catalogs/All Products/Node) if that node's parent is "All Products" with IRelationRepository.GetChildren? From what I can see, the IContentLoader.GetChildren will truly get all the children. Of course it's a bit more expensive loading all that content, but if the example is as small as this and not some bulk thing, it should be negigible.

Sep 12, 2017 16:57

That's true. The direct child nodes are not returned in IRelationRepository.GetChildren, or in CatalogNodeRelation - but that was before I see the picture. :)

Sep 12, 2017 17:09

Hm, my above comment only solves the example, really. 

  • "I want to get all nodes (subtree" 
    If you want to achieve this, with actually getting the children of the children of the children etc, you probably need to do it recursive. As far as I know there isn't any ready function for this.
  • "subtree where relation between nodes can be denifined in [CatalogNodeRelation] and [CatalogNode] table"
    Not entirely sure why this is a requirement, but if it for some reason is, IRelationRepository.GetChildren is the right way to go, as Quan mentioned. (I've explained why in a long post)
  • "from  Mediachase.Commerce.Catalog.Dto.CatalogNodeDto object"
    Again here, not sure why this would be the requirement, my recommendation would really be to use the content objects instead. And not converting the dto to object, but replace it from whererver you fetched the dto.
Sep 12, 2017 17:10

Thank you guys for your quick reply.

The problem here is that our structure is that one node can have more than one Parent, and this information is stored in CatalogNodeRelation.

Now with this structure we have a few problems:

  1. During indexing noderelation from CatalogNodeRelation is not taken into account in _node and _outline field. Actually, I dont know why. But to solve this problem I have overriden BuildPath method and taken care of this.
  2. During incremental indexing, when we move a node (on a picture marked with arrow) and this node does not have entities then this method returns 0.
    int itemsForIndexing = system.StartFindItemsForIndexing(searchSetId, catalogId,
    isIncremental, earliestModifiedDate, latestModifiedDate);

    To solve this we override event, get all child entities and add them to ApplicationLog table. And in this event we have this CatalogNodeDTO. Before an upgrade to Episerver 11 this event fired for every node separately so we just get entities for current node. But after the upgrade it fires just once. (can it be connected with Episerver upgrade?)

    [ServiceConfiguration(typeof(CatalogEventListenerBase), Lifecycle = ServiceInstanceScope.Singleton)]
    public class CatalogListener : CatalogEventListenerBase
    public override void NodeUpdated(object source, NodeEventArgs args)
    var sourceAsCatalogNodeDto = source as Mediachase.Commerce.Catalog.Dto.CatalogNodeDto;

Could you recommend better solution for solving this problems with good performance, since this is one of my biggest interests?

Will code abouve get all nodes accounting CatalogNodeRelation?

var repository = ServiceLocator.Current.GetInstance<IContentLoader>();
var contentLink = referenceConverter.GetContentLink(currentNodeCode);
var nodeCodes = repository.GetChildren<NodeContent>(contentLink).Select(x => x.Code).ToList();

Edited, Sep 12, 2017 17:42
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.