public override async Task <SynchronizeProductArgument> Run(SynchronizeProductArgument arg, CommercePipelineExecutionContext context) { var sellableItem = arg.SellableItem; var variantsComponent = sellableItem.GetComponent <ItemVariationsComponent>(); variantsComponent.ChildComponents.Clear(); foreach (var variant in arg.MasterProduct.ProductVariants) { var displayName = variant?.Values?.FirstOrDefault(f => f.Language == "en")?.Name ?? variant?.Values?.FirstOrDefault()?.Name ?? string.Empty; var variationItem = new ItemVariationComponent { Id = variant.ArticleNr.ProposeValidId(), Name = variant.ArticleNr, DisplayName = displayName }; //Add identifiers var identifiersComponent = variationItem.GetComponent <IdentifiersComponent>(); identifiersComponent.SKU = variant.ArticleNr; identifiersComponent.gtin13 = variant.GTIN; variationItem.SetComponent(identifiersComponent); variantsComponent.ChildComponents.Add(variationItem); } arg.SellableItem = (await _persistEntityPipeline.Run(new PersistEntityArgument(sellableItem), context.CommerceContext.PipelineContextOptions))?.Entity as SellableItem ?? sellableItem; return(arg); }
public override async Task <SynchronizeProductArgument> Run(SynchronizeProductArgument arg, CommercePipelineExecutionContext context) { var sellableItem = arg.SellableItem; var variantsComponent = sellableItem.GetComponent <ItemVariationsComponent>(); variantsComponent.ChildComponents.Clear(); foreach (var variant in arg.ImportProduct.Variants) { var colorProperty = variant.ProductProperties.FirstOrDefault(pp => pp.PropertyId.Equals("11")); var defaultColorValue = colorProperty?.Values?.FirstOrDefault(v => v.Language.Equals("en"))?.Value; var sizeProperty = variant.ProductProperties.FirstOrDefault(pp => pp.PropertyId.Equals("12")); var defaultSizeValue = sizeProperty?.Values?.FirstOrDefault(v => v.Language.Equals("en"))?.Value; var variantId = $"{arg.SellableItem.Name}{defaultColorValue}{defaultSizeValue}"; var variationItem = new ItemVariationComponent() { Id = variantId, Name = $"{arg.SellableItem.DisplayName} {defaultColorValue} {defaultSizeValue}" }; //Add identifiers var identifiersComponent = variationItem.GetComponent <IdentifiersComponent>(); identifiersComponent.SKU = variantId; variationItem.SetComponent(identifiersComponent); variantsComponent.ChildComponents.Add(variationItem); } arg.SellableItem = (await _persistEntityPipeline.Run(new PersistEntityArgument(sellableItem), context.CommerceContext.GetPipelineContextOptions()))?.Entity as SellableItem ?? sellableItem; return(arg); }
public static ProductExtensionComponent GetProductExtensionComponent(SellableItem instance, string variationId) { ItemVariationComponent variation = instance.GetVariation(variationId); if (variation.HasComponent <ProductExtensionComponent>() == false) { var component = instance.GetComponent <ProductExtensionComponent>().Clone(); variation.SetComponent(component); return(component); } else { return(variation.GetComponent <ProductExtensionComponent>()); } }