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/
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());
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 ?
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
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"));(referenceConverter.GetRootLink());
(catalogLink))
var catalogLink = referenceConverter.GetContentLink(lkCatalogId, CatalogContentType.CatalogNode, 0);
contentRepository.GetChildren
foreach (CatalogContentBase child in contentLoader.GetChildren
{
//Do something to the child...
}
I never get into the foreach. Any ideas ?
/Klaus