/// <summary> /// The process of the command /// </summary> /// <param name="commerceContext"> /// The commerce context /// </param> /// <param name="cartId"></param> /// <returns> /// The <see cref="Task"/>. /// </returns> public async Task <Cart> Process(CommerceContext commerceContext, string cartId) { using (var activity = CommandActivity.Start(commerceContext, this)) { var arg = new ResolveCartArgument(commerceContext.CurrentShopName(), cartId, commerceContext.CurrentShopperId()); var cart = await _getCartPipeline.Run(arg, commerceContext.GetPipelineContextOptions()); var cartComponent = cart.GetComponent <TestSimulationComponent>(); cartComponent.Status = true; var persistEntityArgument = await this._persistEntityPipeline.Run(new PersistEntityArgument(cart), commerceContext.GetPipelineContextOptions()); return(cart); } }
public override async Task <CartLineArgument> Run(CartLineArgument arg, CommercePipelineExecutionContext context) { string fulfillmentLocationCart = string.Empty; Condition.Requires(arg).IsNotNull("GetCartLineArticleInfoBlock: Cart can not be null"); var currentSellableItem = context.CommerceContext.GetEntity <SellableItem>(); var currentCartLineArg = context.CommerceContext.GetObject <CartLineArgument>(); Condition.Requires(currentSellableItem).IsNotNull("GetCartLineArticleInfoBlock: Sellable item can not be null"); SellableItemService sellableItemService = new SellableItemService(_getSellableItemPipeline); string fulfillmentLocationItem = sellableItemService.GetFulFilmmentLocationForItem(currentSellableItem); //get the current cart if (!string.IsNullOrEmpty(context.CommerceContext?.Headers["CustomerId"])) { string cartId = "Default" + context.CommerceContext?.Headers["CustomerId"] + context.CommerceContext.CurrentShopName(); var resolveCartArgument = new ResolveCartArgument(context.CommerceContext.CurrentShopName(), cartId, context.CommerceContext.CurrentShopperId()); Cart cart = await this._getCartPipeline.Run(resolveCartArgument, context.CommerceContext.PipelineContextOptions); if (cart != null && cart.Lines != null && cart.Lines.Count > 0) { fulfillmentLocationCart = await sellableItemService.GetFulFilmmentLocationForCartLines(cart.Lines, context); } CommercePipelineExecutionContext executionContext; if (cart.Lines.Count > 0 && fulfillmentLocationCart != fulfillmentLocationItem) { executionContext = context; CommerceContext commerceContext = context.CommerceContext; string error = context.GetPolicy <KnownResultCodes>().Error; object[] args = new object[1] { (object)currentSellableItem.DisplayName }; string defaultMessage = "Item '" + currentSellableItem.DisplayName + "' is not purchasable."; executionContext.Abort(await commerceContext.AddMessage(error, "AddCartFulfillmentErrorMessage", args, defaultMessage).ConfigureAwait(false), (object)context); return((CartLineArgument)null); } } return(arg); }