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.
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.
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))
{
catalogList.Add(catTemp);
}
}
}
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.
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() });
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.
I was haveing the same issue.
Instead of using IContentLoader use IContentRepository.
Not working
var catalogs1 = _contentLoader.GetChildren<CatalogContent>(catalogRootLink);
Working
var catalogs = _contentRepository.GetChildren<CatalogContent>(catalogRootLink);
@David I doubt that was the problem. IContentRepository actually extends IContentLoader.
Make sure you don't make the same mistake I did: https://vimvq1987.com/beware-icontentloader-getchildren/
@Quan I can't speak to the problem anymore as my post was from almost 2-years ago. :)
I know, I was replying to David Fewless :)
As always, it might benefit the future visitors
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.
Thoughts?