/// <summary> /// Import fields defined in Item's composer views /// </summary> /// <param name="commerceEntity"></param> /// <param name="jsonData"></param> /// <param name="mappingPolicy"></param> /// <param name="context"></param> /// <returns></returns> public async Task <SellableItem> ImportComposerViewsFields(SellableItem commerceEntity, Dictionary <string, string> composerFields, CommerceContext context) { var masterView = await _commerceCommander.Command <GetEntityViewCommand>().Process( context, commerceEntity.Id, commerceEntity.EntityVersion, context.GetPolicy <KnownCatalogViewsPolicy>().Master, string.Empty, string.Empty); if (masterView == null) { Log.Error($"Master view not found on Commerce Entity, Entity ID={commerceEntity.Id}"); throw new ApplicationException($"Master view not found on Commerce Entity, Entity ID={commerceEntity.Id}"); } if (masterView.ChildViews == null || masterView.ChildViews.Count == 0) { Log.Error($"No composer-generated views found on Sellable Item entity, Entity ID={commerceEntity.Id}"); throw new ApplicationException($"No composer-generated views found on Sellable Item entity, Entity ID={commerceEntity.Id}"); } var isUpdated = false; foreach (EntityView view in masterView.ChildViews) { EntityView composerViewForEdit = null; foreach (var viewField in view.Properties) { if (composerFields.Keys.Contains(viewField.Name)) { if (composerViewForEdit == null) { composerViewForEdit = Task.Run <EntityView>(async() => await commerceEntity.GetComposerView(view.ItemId, _commerceCommander, context)).Result; } if (composerViewForEdit != null) { var composerProperty = composerViewForEdit.GetProperty(viewField.Name); if (composerViewForEdit != null) { composerProperty.ParseValueAndSetEntityView(composerFields[viewField.Name]); isUpdated = true; } } } } } if (isUpdated) { await _composerCommander.PersistEntity(context, commerceEntity); //var persistResult = await _commerceCommander.Pipeline<IPersistEntityPipeline>().Run(new PersistEntityArgument(commerceEntity), context.PipelineContextOptions); return(await _commerceCommander.Command <FindEntityCommand>().Process(context, typeof(SellableItem), commerceEntity.Id) as SellableItem); } return(commerceEntity); }