5

Followed this tutorial http://world.episerver.com/documentation/commerce/get-started-with-commerce/3--creating-a-start-page/ to get going with episerver commerce. It works fine when writing the url to a specific problem.

But say that I have the following tree.

Catalog Root -> testcatalog -> testlevel -> testproduct 1 and 2

When on testevel (Has the model MyNode if looking at the tutorial), how do I get all child "products", testproduct 1 and 2? It seems like there are 100 ways of doing this.

Using latest episerver and episerver commerce (9).

rickythefox
  • 6,601
  • 6
  • 40
  • 62
noshitsherlock
  • 1,103
  • 2
  • 11
  • 28

1 Answers1

2

Found a way of doing it.

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var products = contentRepository.GetChildren<MyProduct>(Model.ContentLink);

foreach(var product in products)
{
    //Do what you want.
}
noshitsherlock
  • 1,103
  • 2
  • 11
  • 28
  • 1
    Looks about right. :) You can also use `IContentLoader` if you're only interested in retrieving - not saving - content. – Ted Nyberg Apr 07 '16 at 06:16
  • @TedNyberg Aha that is good to know. Thanks :) It's hard to find some "good" tutorials or best practices and usages for episerver. Any good tips? I must say that episervers own site is not that good, at least not when you are used to umbraco :) – noshitsherlock Apr 07 '16 at 10:48