2

I am trying to get the product variants from a SellableItem but I can't seem to be able to find the Variant item.

Below are the steps that I am doing currently

1A) Get sellable item

var sellableItemId = "myid"
SellableItem item = container.SellableItems.Where(x => x.ProductId == sellableItemId ))..FirstOrDefault()

return item.ItemVariations;

1B) This returns a list of variantIds.

"57042066|57042067|57042068|57042069|57042070"

2A) I tried using similar code below to retrieve the variant item, but it is not able to find anything.

var variantId = "57042066";
var variant = container.SellableItems.Where(x => x.ProductId == variantId));
1

You don't need to do 2A step.

SellableItem already contains Sitecore.Commerce.Plugin.Catalog.ItemVariationsComponent. Inside of Sitecore.Commerce.Plugin.Catalog.ItemVariationsComponent you will find ChildComponents property, which contains array of Sitecore.Commerce.Plugin.Catalog.ItemVariationComponent.

See example:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.