Stuck on a little bit of a brain teaser. Currently, I get all product variations via their ContentReference.ID and use this to get an Entry instance in a foreach loop.
if (variationsList != null && variationsList.Count() > 0)
foreach (var item in variationsList)
var thisEntry = CatalogRef.GetCatalogEntry(item.Target.ID, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Variations));
I'm trying to optimise code (cut down database calls) so that we bulk load in CataLogEntries as Entry instances (Probably store these in a dictionary or List). I'm hoping to use the the GetCatalogEntriesDto method to load Entry instances before entering the foreach loop and then using LINQ get a particular Entry instance based on ContentReference.ID something like:
var thisEntry = entryDto.Variation.Single(x => x.CatalogEntryId == item.Target.ID);
Can anyone advise here please?
Is it this you're looking for?
ILinksRepository.GetRelationsBySource(new ContentReference(ParentId)).OfType<ProductVariation>().OrderBy(r => r.SortOrder);
PS, this thread should be posted into the commerce forum
I will try this out - I'll let you know if it works!
Unless you have a specific reason to load the DTO or Entry objects I would really recommend working with the catalog data as IContent using IContentLoader. IContentLoader.GetItems can be used to batch load content.
BTW, don't use the ID part of the content link as the ID of a low-level catalog entity like an entry or node. To convert between ContentReferences and ID:s for catalog entities, use ReferenceConverter.GetObjectId to make sure the conversion is done correctly.
I moved this thread to Commerce forum
What are you trying to do with the Entry(s)? As Rahl said we recommend to use the content APIs (IContentLoader etc.). Loading an Entry also means loading prices and inventories (even when you don't need them), and an Entry object has a quite poor reuseable so caching is pretty limited.
I'm trying to bulk load entries via the GetCatalogEntriesDto so I can access the ItemAttributes of the Entry, does that make sense?
When you load the IContent you can access the properties via Property. Or even better, if you use strongly typed content types, inherited from ProductContent, VariantionContent, etc., you can access the properties in a strong typed maner, so instead of ItemAttributes["AHiddeTypo"], you can make it productContent.AHiddenTypo.
Spot the difference?
The IContentLoader solution worked for me!
Thannks for all your help!