public ActionResult CreateShipment(ShippingPickerViewModel createShipmentViewModel)
        {
            var cartService = new CartServiceProvider();
            var cart        = GetCart();

            if (cart.Shipping.Any())
            {
                var removeRequest = new RemoveShippingInfoRequest(cart, cart.Shipping.ToList());
                var removeResult  = cartService.RemoveShippingInfo(removeRequest);
            }

            var shippingParty = cart.Parties.FirstOrDefault(x => x.PartyId == Constants.DefaultShipmentAddressName);
            var shippingList  = new List <ShippingInfo>
            {
                new ShippingInfo()
                {
                    ShippingMethodID = createShipmentViewModel.SelectedShippingMethodId.ToString(),
                    PartyID          = shippingParty.PartyId
                }
            };

            var addRequest = new AddShippingInfoRequest(cart, shippingList);
            var addResult  = cartService.AddShippingInfo(addRequest);

            return(Redirect("/payment"));
        }
        public PipelineExecutionResult Execute(IPipelineArgs <CreateShipmentRequest, CreateShipmentResult> subject)
        {
            if (subject.Request.Properties.ContainsKey("FromUCommerce"))
            {
                if (!(bool)subject.Request.Properties["FromUCommerce"])
                {
                    return(PipelineExecutionResult.Success);
                }
            }

            var cart = MappingLibrary.MapPurchaseOrderToCart(subject.Request.PurchaseOrder);

            var cartService  = new CartServiceProvider();
            var shippingList = new List <ShippingInfo>
            {
                new ShippingInfo()
                {
                    ShippingMethodID = subject.Request.ShippingMethod.ShippingMethodId.ToString()
                }
            };
            var request = new AddShippingInfoRequest(cart, shippingList);

            request.Properties["FromUCommerce"] = true;

            var result = cartService.AddShippingInfo(request);

            return(PipelineExecutionResult.Success);
        }
        /// <summary>
        /// Adds shipping info to a cart
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <param name="orderShippingPreferenceType">Type of the order shipping preference.</param>
        /// <param name="shipments">The shipments.</param>
        /// <returns>
        /// the updated cart
        /// </returns>
        protected virtual AddShippingInfoResult AddShippingInfoToCart([NotNull] CommerceCart cart, [NotNull] ShippingOptionType orderShippingPreferenceType, [NotNull] IEnumerable<ShippingInfo> shipments)
        {
            Assert.ArgumentNotNull(cart, "cart");
            Assert.ArgumentNotNull(orderShippingPreferenceType, "orderShippingPreferenceType");
            Assert.ArgumentNotNull(shipments, "shipments");

            var request = new AddShippingInfoRequest(cart, shipments.ToList());
            request.RefreshCart(true);
            var result = this.CartServiceProvider.AddShippingInfo(request);
            if (!result.Success)
            {
                Helpers.LogSystemMessages(result.SystemMessages, result);
            }

            return result;
        }