Vulnerability in EPiServer.Forms

Try our conversational search powered by Generative AI!

Get ALL commerce catalogs


Can anyone tell me how to retrieve all catalogs out of commerce?  I'm not sure if I am missing something simple or if this is a bug. I am creating a scheduled task where I need to loop through our catalogs and perform some tasks on them.  I thought the following line of code would work, but discovered that one of our catalogs is not coming back in the results.  

var catalogs = _contentLoader.GetChildren(_referenceConverter.GetRootLink());

We have catalog A with languages of en-us, en-ca, and fr-ca.

We have catalog B with language of en-us

We have catalog C with languages of en-ca and fr-ca

When I call the code above, I only get catalog A and B back.  So finally, I went to catalog C and added en-us as an available language to see if I got it back in the call.  When I run the code, I in fact will get it back in the results.  I then removed en-us as an available language for C and made the call again, and C is not in the results. 

Worst case scenario, I loop through the ILanguageBranchRepository.ListEnabled() and add each distinct catalog I find to my own list to loop through, but that just seems dumb that I would have to go down that path.


May 05, 2016 4:28

This is a wild guess but I had a smililar problem a while back and in my case it was due to permissions for the user is being used to run the scheduled job.
Try setting a specific user in the code, preferably an admin account, and see if this solves the issue.

May 05, 2016 8:16

I actually went down that path too based on something a co-worker told me based on how the scheduled tasks run, but unfortunately that was not the issue, still do not get the one catalog back.

May 05, 2016 15:50

Still was unable to get anything to get it back correctly, so I ended up coding this out to meet my needs:

var languageBranch = _languageBranch.Service.ListEnabled();
var catalogList = new List<CatalogContent>();

foreach (var lang in languageBranch) {
    var catList = _contentLoader.Service.GetChildren<CatalogContent>(_referenceConverter.Service.GetRootLink(), new LanguageSelector(lang.LanguageID))   

    foreach(var catTemp in catList)
        if (!catalogList.Exists(x => x.CatalogId == catTemp.CatalogId))

This meets my needs, but it still doesn't make sense as to why my original code wasn't bringing back the one catalog that didn't have en-us as an available language.

May 05, 2016 22:48

What is set as the master language?

For making the content loader fall back to a specific language you could do

var fallbackCulture = new CultureInfo("en-US");

_contentLoader.Service.GetChildren<CatalogContent>(_referenceConverter.Service.GetRootLink(), new LoaderOptions() { LanguageLoaderOption.FallbackWithMaster(fallbackCulture) });

Or always fetch from master language

_contentLoader.Service.GetChildren<CatalogContent>(_referenceConverter.Service.GetRootLink(), new LoaderOptions() { LanguageLoaderOption.MasterLanguage() });

May 16, 2016 15:19

I guess really the net issue I was trying to solve is how come this:

var catalogs = _contentLoader.GetChildren<CatalogContent>(_referenceConverter.GetRootLink());

Doesn't correctly return me all catalogs as it should.  

That being said, in response to the previouse comment, our master language is en-us, so setting the master language would still not get us back catalog C with languages of en-ca and fr-ca.

May 16, 2016 16:24

Try using this as language selector...
May 16, 2016 17:29

Is catalog Enabled?

May 17, 2016 19:07

It sure is.

May 17, 2016 20:44

I was haveing the same issue. 

Instead of using IContentLoader use IContentRepository. 

Not working 

var catalogs1 = _contentLoader.GetChildren<CatalogContent>(catalogRootLink);


var catalogs = _contentRepository.GetChildren<CatalogContent>(catalogRootLink);

Apr 18, 2018 21:59

@David I doubt that was the problem. IContentRepository actually extends IContentLoader.

Make sure you don't make the same mistake I did: 

Apr 18, 2018 22:10

@Quan I can't speak to the problem anymore as my post was from almost 2-years ago. :)

Apr 18, 2018 22:13

I know, I was replying to David Fewless :) 

As always, it might benefit the future visitors 

Apr 18, 2018 22:19
* 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.