Getting children of Catalog

Vote:
 

Hey,

I want to loop through all the a Catalog, but i always seem to get null

Here is how i try to do it:

var lkCatalogId = int.Parse(ConfigurationManager.AppSettings.Get("LKCatalogRoot"));
            var catalogLink = referenceConverter.GetContentLink(lkCatalogId, CatalogContentType.CatalogNode, 0);
            contentRepository.GetChildren(referenceConverter.GetRootLink());

            foreach (CatalogContentBase child in contentLoader.GetChildren(catalogLink))
            {
                //Do something to the child...
            }

I never get into the foreach. Any ideas ?

/Klaus

#132726
Aug 18, 2015 10:47
Vote:
 

This will give you the first level children of the catalog root:

var children = ContentLoader.GetChildren<CatalogContent>(ReferenceConverter.GetRootLink());

            foreach (CatalogContent child in children)
            {
                //Do something to the child...
            }

To better understand how the Commerce API works, I recommend reading the following blog post:

http://geta.no/blogg/working-with-the-episerver-7.5-commerce-api/

#132732
Aug 18, 2015 12:27
Vote:
 
var referenceConverter = context.Locate.Advanced.GetInstance<Mediachase.Commerce.Catalog.ReferenceConverter>();
var contentLoader = context.Locate.Advanced.GetInstance<IContentLoader>();

var commerceRootContent = contentLoader.Get<Commerce.Catalog.ContentTypes.CatalogContentBase>(referenceConverter.GetRootLink());


#132733
Edited, Aug 18, 2015 12:31
Vote:
 

Hey,

I guess i didnt describe it very well, but i am trying to get children of Catalog nodes - not CatalogRoot nodes.

So in below structure i want Category A, B and C:

CatalgoRoot- LK Catalog'
- - Category A
- - Category B
- - Category C

Any ideas ?

#132747
Aug 18, 2015 17:46
Vote:
 

Hi,

This should work for you:

var lkCatalogId = int.Parse(ConfigurationManager.AppSettings.Get("LKCatalogRoot"));
            var catalogLink = referenceConverter.GetContentLink(lkCatalogId, CatalogContentType.Catalog, 0);

            foreach (CatalogContentBase child in contentLoader.GetChildren<NodeContent>(catalogLink))
            {
                //Do something to the child...
            }

Don't know why my previous is missing :) . But the idea is that if LKCatalogRoot is a catalog id, then you must use CatalogContentType.Catalog to get it contentReference.

Regards.

/Q

#132817
Aug 19, 2015 6:43
* 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.