public ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> > GetShippingMethods(string userId, GetShippingMethodsInputModel inputModel)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));

            var result = new GetShippingMethodsResult {
                Success = false
            };
            var cartResult = CartManager.GetCart(userId);

            if (!cartResult.ServiceProviderResult.Success || cartResult.Result == null)
            {
                result.SystemMessages.ToList().AddRange(cartResult.ServiceProviderResult.SystemMessages);
                return(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >(result, null));
            }

            var cart           = cartResult.Result;
            var preferenceType = InputModelExtension.GetShippingOptionType(inputModel.ShippingPreferenceType);

            var request = new GetShippingMethodsRequest(new ShippingOption {
                ShippingOptionType = preferenceType
            }, inputModel.ShippingAddress?.ToParty(), cart)
            {
                Lines = inputModel.Lines?.ToCommerceCartLines()
            };

            result = ShippingServiceProvider.GetShippingMethods <Sitecore.Commerce.Services.Shipping.GetShippingMethodsRequest, GetShippingMethodsResult>(request);
            return(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >(result, result.ShippingMethods));
        }
        private ReadOnlyCollection <ShippingMethod> GetShippingMethods(ShippingOption shippingOption, Cart cart)
        {
            var shippingService = new ShippingServiceProvider();
            var shippingParty   = cart.Parties.FirstOrDefault(x => x.PartyId == Constants.DefaultShipmentAddressName);
            var party           = cart.Parties.FirstOrDefault(x => x.PartyId == shippingParty.PartyId);

            var request = new GetShippingMethodsRequest(shippingOption, party);

            return(shippingService.GetShippingMethods(request).ShippingMethods);
        }
Beispiel #3
0
        public ActionResult GetCartLineFulfillmentMethods()
        {
            // Load a cart
            var loadCartRequest = new LoadCartRequest("CommerceEngineDefaultStorefront", "Default", "1234");
            var loadCartResult  = _cartServiceProvider.LoadCart(loadCartRequest);
            var cart            = loadCartResult.Cart as CommerceCart;

            // Add a line to the cart
            var lines    = new List <CartLine>();
            var cartLine = new CommerceCartLine("NEU", "test", "", 1.0M);

            lines.Add(cartLine);

            var addLinesRequest = new AddCartLinesRequest(cart, lines);
            var addLinesResult  = _cartServiceProvider.AddCartLines(addLinesRequest);

            cart = addLinesResult.Cart as CommerceCart;

            var shippingService = new ShippingServiceProvider();

            var shippingOption = new ShippingOption
            {
                ShippingOptionType =
                    ShippingOptionType
                    .DeliverItemsIndividually,     // This will trigger calling GetCartLinesFulfillmentMethods instead of GetCartFulfillmentMethods
            };

            var shippingParty = new CommerceParty
            {
                Address1    = "Main Street", City = "Montreal", ZipPostalCode = "NW7 7SJ", Country = "Canada",
                CountryCode = "CA"
            };

            var request = new GetShippingMethodsRequest(shippingOption, shippingParty, cart)
            {
                Lines = cart.Lines.Cast <CommerceCartLine>().ToList()
            };
            var result = shippingService.GetShippingMethods(request);

            return(View(result));
        }