Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get products episerver commerce

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).

like image 805
noshitsherlock Avatar asked Oct 31 '22 06:10

noshitsherlock


1 Answers

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.
}
like image 64
noshitsherlock Avatar answered Nov 15 '22 09:11

noshitsherlock