예제 #1
0
        public override void Process(ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.Request");
            Assert.ArgumentNotNull(args.Result, "args.Result");
            Assert.IsTrue((bool)(args.Request is SubmitVisitorOrderRequest), "args.Request is SubmitVisitorOrderRequest");
            Assert.IsTrue((bool)(args.Result is SubmitVisitorOrderResult), "args.Result is SubmitVisitorOrderResult");

            SubmitVisitorOrderRequest request = (SubmitVisitorOrderRequest)args.Request;
            SubmitVisitorOrderResult  result  = (SubmitVisitorOrderResult)args.Result;
            CartPipelineContext       context = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(context, "cartContext");

            if (((context.Basket != null) && !context.HasBasketErrors) && result.Success)
            {
                foreach (OrderForm orderForm in context.Basket.OrderForms)
                {
                    foreach (LineItem lineItem in orderForm.LineItems)
                    {
                        var cartLine = request.Cart.Lines.FirstOrDefault(l => l.ExternalCartLineId.Equals(lineItem.LineItemId.ToString("B"), StringComparison.OrdinalIgnoreCase));
                        if (cartLine == null)
                        {
                            continue;
                        }

                        // Store the image as a string since a dictionary is not serializable and causes problems in C&OM.
                        StringBuilder imageList = new StringBuilder();
                        foreach (MediaItem image in ((CustomCommerceCartLine)cartLine).Images)
                        {
                            if (image != null)
                            {
                                if (imageList.Length > 0)
                                {
                                    imageList.Append("|");
                                }

                                imageList.Append(image.ID.ToString());
                                imageList.Append(",");
                                imageList.Append(image.MediaPath);
                            }
                        }

                        lineItem["Images"] = imageList.ToString();
                    }
                }

                PurchaseOrder orderGroup = context.Basket.SaveAsOrder();
                TranslateOrderGroupToEntityRequest request2 = new TranslateOrderGroupToEntityRequest(context.UserId, context.ShopName, orderGroup);
                TranslateOrderGroupToEntityResult  result2  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>("translate.orderGroupToEntity", request2);
                result.Order = result2.Cart as Order;
            }
        }
예제 #2
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Commerce.Pipelines.ServicePipelineArgs args)
        {
            base.Process(args);

            var cartContext = CartPipelineContext.Get(args.Request.RequestContext);

            Assert.IsNotNullOrEmpty(cartContext.UserId, "cartContext.UserId");
            Assert.IsNotNullOrEmpty(cartContext.ShopName, "cartContext.ShopName");

            if (cartContext.HasBasketErrors && !args.Result.Success)
            {
                args.Result.Success = true;
            }
        }
예제 #3
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Sitecore.Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");

            RemovePartiesRequest request = (RemovePartiesRequest)args.Request;
            RemovePartiesResult  result  = (RemovePartiesResult)args.Result;

            var cartContext = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(cartContext, "cartContext");

            List <Party> partiesRemoved = new List <Party>();

            if (cartContext.Basket != null)
            {
                foreach (Party party in request.Parties)
                {
                    if (party != null)
                    {
                        Assert.ArgumentNotNullOrEmpty(party.ExternalId, "party.ExternalId");

                        OrderAddress orderAddress = cartContext.Basket.Addresses[party.ExternalId];
                        if (orderAddress != null)
                        {
                            cartContext.Basket.Addresses.Remove(orderAddress);

                            partiesRemoved.Add(party);
                        }
                    }
                }
            }

            result.Parties = partiesRemoved;

            // Needed by the RunSaveCart CommerceConnect pipeline.
            var translateCartRequest = new TranslateOrderGroupToEntityRequest(cartContext.UserId, cartContext.ShopName, cartContext.Basket);
            var translateCartResult  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>(PipelineNames.TranslateOrderGroupToEntity, translateCartRequest);

            result.Cart = translateCartResult.Cart;
        }
예제 #4
0
        /// <summary>
        /// Processes the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public override void Process(Sitecore.Commerce.Pipelines.ServicePipelineArgs args)
        {
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.request");

            AddPartiesRequest request = (AddPartiesRequest)args.Request;
            AddPartiesResult  result  = (AddPartiesResult)args.Result;

            var cartContext = CartPipelineContext.Get(request.RequestContext);

            Assert.IsNotNull(cartContext, "cartContext");

            List <Party> partiesAdded = new List <Party>();

            if (cartContext.Basket != null)
            {
                foreach (Party party in request.Parties)
                {
                    Party newParty;

                    if (party == null)
                    {
                        continue;
                    }

                    newParty = this.ProcessParty(party, cartContext);

                    partiesAdded.Add(newParty);
                }
            }

            result.Parties = partiesAdded;

            // Needed by the RunSaveCart CommerceConnect pipeline.
            var translateCartRequest = new TranslateOrderGroupToEntityRequest(cartContext.UserId, cartContext.ShopName, cartContext.Basket);
            var translateCartResult  = PipelineUtility.RunCommerceConnectPipeline <TranslateOrderGroupToEntityRequest, TranslateOrderGroupToEntityResult>(PipelineNames.TranslateOrderGroupToEntity, translateCartRequest);

            result.Cart = translateCartResult.Cart;
        }