public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context) { if (entityView == null || !entityView.Action.Equals(context.GetPolicy <SettingsUiPolicy>().DeleteSettingActionName, StringComparison.OrdinalIgnoreCase)) { return(entityView); } string targetId = string.IsNullOrEmpty(entityView.EntityId) ? entityView.ItemId : entityView.EntityId; try { var setting = await _commerceCommander.Command <GetSettingCommand>().Process(context.CommerceContext, targetId); if (setting == null) { return(entityView); } await _commerceCommander.DeleteEntity(context.CommerceContext, setting); } catch (Exception ex) { context.Logger.LogError($"{this.Name}.PathNotFound: Message={ex.Message}"); } return(entityView); }
protected async Task ImportInventoryInformation(CommercePipelineExecutionContext context, CommerceEntity commerceEntity, string inventorySetId, string variantId, InventoryDetail inventoryDetail) { var result = await GetInventoryInformation(context, commerceEntity, inventorySetId, variantId) .ConfigureAwait(false); if (inventoryDetail != null) { if (result.Item2) { await _commerceCommander.Command <EditInventoryInformationCommand>() .Process(context.CommerceContext, commerceEntity.Id, variantId, inventorySetId, ConvertToEntityView(inventoryDetail)); } else { await _commerceCommander.Command <AssociateSellableItemToInventorySetCommand>() .Process(context.CommerceContext, commerceEntity.Id, variantId, inventorySetId, ConvertToEntityView(inventoryDetail)) .ConfigureAwait(false); } } else { if (result.Item2) { await _commerceCommander.Command <DisassociateSellableItemFromInventorySetCommand>() .Process(context.CommerceContext, commerceEntity.Id, variantId, inventorySetId); } else if (result.Item1 != null) { await _commerceCommander.DeleteEntity(context.CommerceContext, result.Item1) .ConfigureAwait(false); } } }
private async void CreateBlockchainInformationTemplate(CommercePipelineExecutionContext context) { string templateId = $"{CommerceEntity.IdPrefix<ComposerTemplate>()}{"BlockchainInformation"}"; try { // delete the existing template (this does not delete data from products) var deleteTemplate = await _commerceCommander.DeleteEntity(context.CommerceContext, templateId); var composerTemplate = new ComposerTemplate(templateId); composerTemplate.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <ComposerTemplate>()); composerTemplate.Tags.Add(new Tag("Blockchain")); composerTemplate.Name = "BlockchainInformation"; composerTemplate.DisplayName = "Blockchain Information"; var composerTemplateViewComponent = composerTemplate.GetComponent <EntityViewComponent>(); composerTemplateViewComponent.Id = "95DACDDD-151E-4527-A068-A27C9275967J"; var composerTemplateView = new EntityView { Name = Constants.Pipelines.Views.BlockchainInformationViewName, DisplayName = Constants.Pipelines.Views.BlockchainInformationViewDisplayName, DisplayRank = 0, ItemId = Constants.Pipelines.Views.BlockchainInformationViewId, EntityId = composerTemplate.Id }; composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "Identity Contract Address", Name = Constants.Pipelines.Fields.IdentityContractAddressFieldName, OriginalType = "System.String", RawValue = "", Value = "" }); composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "Publish Purchased Products", Name = Constants.Pipelines.Fields.PublishProductsFieldName, OriginalType = "System.Boolean", RawValue = false, Value = "false" }); composerTemplateView.Properties.Add(new ViewProperty() { IsRequired = false, DisplayName = "ETH Balance", Name = Constants.Pipelines.Fields.EthBalanceFieldName, OriginalType = "System.String", RawValue = string.Empty, Value = string.Empty, IsReadOnly = true }); composerTemplateViewComponent.View.ChildViews.Add(composerTemplateView); var persistResult = await this._commerceCommander.PersistEntity(context.CommerceContext, composerTemplate); } catch (Exception ex) { context.Logger.LogError(string.Format("{0}. Unable to generate Composer tamplate '{1}'. {2}", Constants.Pipelines.Blocks.CreateComposerTemplatesBlock, templateId, ex.Message), Array.Empty <object>()); } }