private ReadOnlyCollection <ShippingOption> GetShippingOptions()
        {
            var shippingService = new ShippingServiceProvider();
            var request         = new GetShippingOptionsRequest();

            return(shippingService.GetShippingOptions(request).ShippingOptions);
        }
Пример #2
0
        public override void Process(ServicePipelineArgs args)
        {
            // validate args
            Assert.ArgumentNotNull(args, "args");
            Assert.ArgumentNotNull(args.Request, "args.Request");
            Assert.ArgumentNotNull(args.Request.RequestContext, "args.Request.RequestContext");
            Assert.ArgumentNotNull(args.Result, "args.Result");
            GetShippingOptionsRequest request = args.Request as GetShippingOptionsRequest;
            GetShippingOptionsResult  result  = args.Result as GetShippingOptionsResult;

            Assert.IsNotNull(request, "The parameter args.Request was not of the expected type.  Expected {0}.  Actual {1}.", typeof(GetShippingOptionsRequest).Name, args.Request.GetType().Name);
            Assert.IsNotNull(result, "The parameter args.Result was not of the expected type.  Expected {0}.  Actual {1}.", typeof(GetShippingOptionsResult).Name, args.Result.GetType().Name);

            try
            {
                Assert.ArgumentNotNull(request.Cart, "request.Cart");
                Assert.IsTrue(request.Cart.Lines.Count > 0, "request.Cart.Lines");
                string cartId = request.Cart.ExternalId;
                List <CartFulfillment> cartFulfillments = Proxy.Execute(this.GetContainer(request.Cart.ShopName, request.Cart.UserId, request.Cart.CustomerId, "", args.Request.CurrencyCode, new DateTime?()).GetCartWithFulfillmentOptions(cartId).Expand("FulfillmentOptions")).ToList();
                DataServiceCollection <FulfillmentOption> fulfillmentOptions = cartFulfillments.FirstOrDefault(k => k.TargetId == cartId)?.FulfillmentOptions;
                if (fulfillmentOptions == null || !fulfillmentOptions.Any())
                {
                    result.Success = false;
                    return;
                }
                List <ShippingOption>     shippingOptions        = fulfillmentOptions.Select(this.TranslateShippingOption).ToList();
                List <LineShippingOption> lineShippingOptionList = new List <LineShippingOption>();

                foreach (CartLine cartLine in request.Cart.Lines)
                {
                    CartLine line = cartLine;
                    DataServiceCollection <FulfillmentOption> lineFulfillmentOptions = cartFulfillments.FirstOrDefault(k => k.TargetId == line.ExternalCartLineId)?.FulfillmentOptions;
                    if (!lineFulfillmentOptions.Any())
                    {
                        result.Success = false;
                        return;
                    }
                    List <ShippingOption> lineShippingOptions = lineFulfillmentOptions.Select(this.TranslateShippingOption).ToList();
                    LineShippingOption    lineShippingOption  = this.EntityFactory.Create <LineShippingOption>("LineShippingOption");
                    lineShippingOption.LineId          = line.ExternalCartLineId;
                    lineShippingOption.ShippingOptions = lineShippingOptions;
                    lineShippingOptionList.Add(lineShippingOption);
                }

                result.ShippingOptions         = shippingOptions.AsReadOnly();
                result.LineShippingPreferences = lineShippingOptionList.AsReadOnly();
            }
            catch (ArgumentException ex)
            {
                result.Success = false;
                result.SystemMessages.Add(new SystemMessage(ex.Message));
            }
            base.Process(args);
        }
        public virtual ManagerResponse <GetShippingOptionsResult, List <ShippingOption> > GetShippingPreferences(Cart cart)
        {
            var request = new GetShippingOptionsRequest(cart);
            GetShippingOptionsResult shippingOptions = this.shippingServiceProvider.GetShippingOptions(request);

            if (shippingOptions.Success && shippingOptions.ShippingOptions != null)
            {
                return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(shippingOptions, shippingOptions.ShippingOptions.ToList()));
            }
            return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(shippingOptions, null));
        }
Пример #4
0
        public GetShippingOptionsResponse Invoke(GetShippingOptionsRequest request)
        {
            using (var sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\Shipping.xml")))
            {
                var ser      = sr.ReadToEnd();
                var response = new GetShippingOptionsResponse()
                {
                    ShippingOptions =
                        SerializationHelper.
                        DataContractDeserialize <Dictionary <string, ShippingBase> >(ser)
                };

                return(response);
            }
        }
Пример #5
0
        /// <summary>
        /// Gets the shipping preferences.
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <returns>The manager response where the shipping options are returned in the Result.</returns>
        public ManagerResponse <GetShippingOptionsResult, List <ShippingOption> > GetShippingPreferences([NotNull] Cart cart)
        {
            Assert.ArgumentNotNull(cart, "cart");

            var request = new GetShippingOptionsRequest(cart);
            var result  = this.ShippingServiceProvider.GetShippingOptions(request);

            if (result.Success && result.ShippingOptions != null)
            {
                return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(result, result.ShippingOptions.ToList()));
            }

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(result, null));
        }
        public ManagerResponse <GetShippingOptionsResult, List <ShippingOption> > GetShippingPreferences(Cart cart)
        {
            Assert.ArgumentNotNull(cart, nameof(cart));

            var request = new GetShippingOptionsRequest(cart);
            var result  = ShippingServiceProvider.GetShippingOptions(request);

            if (result.Success && result.ShippingOptions != null)
            {
                return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(result, result.ShippingOptions.ToList()));
            }

            result.WriteToSitecoreLog();
            return(new ManagerResponse <GetShippingOptionsResult, List <ShippingOption> >(result, null));
        }
        public GetShippingOptionsResponse Invoke(GetShippingOptionsRequest request)
        {
            using (var sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"App_Data\Shipping.xml")))
            {
                var ser = sr.ReadToEnd();
                var response = new GetShippingOptionsResponse()
                                   {
                                       ShippingOptions =
                                           SerializationHelper.
                                           DataContractDeserialize<Dictionary<string, ShippingBase>>(ser)
                                   };

                return response;
            }
        }
        /// <summary>
        /// Gets the shipping preferences.
        /// </summary>
        /// <param name="cart">The cart.</param>
        /// <returns>The manager response where the shipping options are returned in the Result.</returns>
        public ManagerResponse<GetShippingOptionsResult, List<ShippingOption>> GetShippingPreferences([NotNull] Cart cart)
        {
            Assert.ArgumentNotNull(cart, "cart");

            var request = new GetShippingOptionsRequest(cart);
            var result = this.ShippingServiceProvider.GetShippingOptions(request);
            if (result.Success && result.ShippingOptions != null)
            {
                return new ManagerResponse<GetShippingOptionsResult, List<ShippingOption>>(result, result.ShippingOptions.ToList());
            }

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<GetShippingOptionsResult, List<ShippingOption>>(result, null);
        }