protected override async Task RemoveAdditionalDependencies( RemoveAllPriceBooksArgument arg, CommercePipelineExecutionContext context, PriceBook entity) { Condition.Requires(arg, nameof(arg)).IsNotNull(); Condition.Requires(context, nameof(context)).IsNotNull(); Condition.Requires(entity, nameof(entity)).IsNotNull(); var relationshipDef = new RelationshipDefinition(Array.Empty <Component>()) { Name = "PriceBookToCatalog" }; var entitiesInListArgument = new FindEntitiesInListArgument(typeof(Catalog), CatalogExportHelper.GetRelationshipListName(entity, relationshipDef), 0, int.MaxValue) { LoadEntities = false, LoadTotalItemCount = false }; foreach (var entityReference in (await Commander.Pipeline <IFindEntitiesInListPipeline>() .Run(entitiesInListArgument, context).ConfigureAwait(false)).EntityReferences) { var inventorySetArgument = new CatalogAndBookArgument(entity.FriendlyId, entityReference.EntityId.SimplifyEntityName()); await Commander.Pipeline <IDisassociateCatalogFromBookPipeline>() .Run(inventorySetArgument, context).ConfigureAwait(false); } }
private async Task AssociateCatalogToBook(string bookName, string catalogName, CommercePipelineExecutionContext context) { // To persist entities conventionally and to prevent any race conditions, create a separate CommercePipelineExecutionContext object and CommerceContext object. var pipelineExecutionContext = new CommercePipelineExecutionContext(new CommerceContext(context.CommerceContext.Logger, context.CommerceContext.TelemetryClient) { GlobalEnvironment = context.CommerceContext.GlobalEnvironment, Environment = context.CommerceContext.Environment, Headers = new HeaderDictionary(context.CommerceContext.Headers.ToDictionary(x => x.Key, y => y.Value)) // Clone current context headers by shallow copy. }.PipelineContextOptions, context.CommerceContext.Logger); // To persist entities conventionally, remove policy keys in the newly created CommerceContext object. pipelineExecutionContext.CommerceContext.RemoveHeader(CoreConstants.PolicyKeys); var arg = new CatalogAndBookArgument(bookName, catalogName); await _associateCatalogToBookPipeline.Run(arg, pipelineExecutionContext).ConfigureAwait(false); }
private async Task AssociateCatalogToBook(string bookName, string catalogName, CommercePipelineExecutionContext context) { var arg = new CatalogAndBookArgument(bookName, catalogName); await _associateCatalogToBookPipeline.Run(arg, context).ConfigureAwait(false); }