Esempio n. 1
0
        /// <summary>
        /// Gets the shipping methods.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="inputModel">The input model.</param>
        /// <returns>
        /// The manager response where the shipping methods are returned in the Result.
        /// </returns>
        public ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> > GetShippingMethods([NotNull] CommerceStorefront storefront, [NotNull] VisitorContext visitorContext, [NotNull] GetShippingMethodsInputModel inputModel)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            Assert.ArgumentNotNull(inputModel, "inputModel");

            GetShippingMethodsResult result = new GetShippingMethodsResult {
                Success = false
            };
            var cartResult = this.CartManager.GetCurrentCart(storefront, visitorContext);

            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 Sitecore.Commerce.Engine.Connect.Services.Shipping.GetShippingMethodsRequest(
                new ShippingOption {
                ShippingOptionType = preferenceType
            },
                (inputModel.ShippingAddress != null) ? inputModel.ShippingAddress.ToParty() : null,
                cart)
            {
                Lines = (inputModel.Lines != null) ? inputModel.Lines.ToCommerceCartLines() : null
            };

            result = this.ShippingServiceProvider.GetShippingMethods <GetShippingMethodsRequest, GetShippingMethodsResult>(request);
            return(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >(result, result.ShippingMethods));
        }
        public ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> > GetShippingMethods(
            string shopName,
            Cart cart,
            ShippingOptionType shippingOptionType,
            PartyEntity address,
            List <string> cartLineExternalIdList)
        {
            if (cartLineExternalIdList != null && cartLineExternalIdList.Any <string>())
            {
            }

            CommerceParty commerceParty = null;

            if (address != null)
            {
                commerceParty = this.connectEntityMapper.MapToCommerceParty(address);
            }

            var shippingOption = new ShippingOption {
                ShippingOptionType = shippingOptionType
            };
            var request = new Sitecore.Commerce.Engine.Connect.Services.Shipping.GetShippingMethodsRequest(shippingOption, commerceParty, cart as CommerceCart);
            GetShippingMethodsResult shippingMethods = this.shippingServiceProvider.GetShippingMethods <GetShippingMethodsRequest, GetShippingMethodsResult>(request);

            return(new ManagerResponse <GetShippingMethodsResult, IReadOnlyCollection <ShippingMethod> >(shippingMethods, shippingMethods.ShippingMethods));
        }
        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));
        }
Esempio n. 4
0
        public GetShippingMethodsResult GetShippingMethods(Cart cart, ShippingOptionType shippingOptionType)
        {
            Assert.ArgumentNotNull(cart, nameof(cart));
            Assert.ArgumentNotNull(shippingOptionType, nameof(shippingOptionType));

            var shippingOption = new ShippingOption
            {
                ShippingOptionType = shippingOptionType
            };
            var request = new GetShippingMethodsRequest(shippingOption, null, cart as CommerceCart);

            return(this.Execute(request, this.shippingServiceProvider.GetShippingMethods));
        }
Esempio n. 5
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));
        }