Ejemplo n.º 1
0
        public List <PaypalShippingOption> Get(PaypalShippingInfo info)
        {
            CartModel cart = _paypalExpressCartLoader.GetCart(info.Token);

            if (cart == null)
            {
                return(new List <PaypalShippingOption>());
            }

            _cartManager.SetShippingAddress(info.ToAddress(), cart.UserGuid);

            cart = _cartBuilder.BuildCart(cart.UserGuid);

            IOrderedEnumerable <IShippingMethod> orderedEnumerable = _shippingMethodUIService.GetEnabledMethods()
                                                                     .FindAll(method => method.CanBeUsed(cart))
                                                                     .OrderBy(method => method.GetShippingTotal(cart));

            List <PaypalShippingOption> paypalShippingOptions = orderedEnumerable.Select(x => new PaypalShippingOption
            {
                Amount          = x.GetShippingTotal(cart),
                Default         = false,
                InsuranceAmount = 0m,
                DisplayName     = x.DisplayName,
                Label           = string.Format("({0})", x.Name),
                TotalTax        = cart.ItemTax
            }).ToList();

            if (paypalShippingOptions.Any())
            {
                paypalShippingOptions[0].Default = true;
            }
            return(paypalShippingOptions);
        }
Ejemplo n.º 2
0
        private bool SetShippingMethod(GetExpressCheckoutDetailsResponseDetailsType details)
        {
            UserSelectedOptionType userSelectedOptions = details.UserSelectedOptions;
            bool shippingMethodSet = false;

            if (userSelectedOptions != null)
            {
                string shippingOptionName = userSelectedOptions.ShippingOptionName;
                if (string.IsNullOrWhiteSpace(shippingOptionName))
                {
                    return(false);
                }
                HashSet <IShippingMethod> enabledMethods = _shippingMethodUiService.GetEnabledMethods();
                IShippingMethod           shippingMethod =
                    enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.TypeName)) ??
                    enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.Name)) ??
                    enabledMethods.FirstOrDefault(method => shippingOptionName.StartsWith(method.DisplayName));
                if (shippingMethod != null)
                {
                    _cartManager.SetShippingMethod(shippingMethod);
                    shippingMethodSet = true;
                }
            }
            return(shippingMethodSet);
        }
Ejemplo n.º 3
0
        public IEnumerable <GoogleBaseCalculationInfo> GetCheapestCalculationsForEachCountry(CartModel cart)
        {
            IList <Country>           countries       = _session.QueryOver <Country>().Cacheable().List();
            HashSet <IShippingMethod> shippingMethods = _shippingMethodUIService.GetEnabledMethods();

            foreach (Country country in countries)
            {
                cart.ShippingAddress = new Address
                {
                    CountryCode = country.ISOTwoLetterCode
                };
                HashSet <IShippingMethod> availableMethods =
                    shippingMethods.FindAll(method => method.CanPotentiallyBeUsed(cart));
                if (availableMethods.Any())
                {
                    IShippingMethod shippingMethod =
                        availableMethods.OrderBy(method => method.GetShippingTotal(cart)).First();
                    yield return(new GoogleBaseCalculationInfo
                    {
                        CountryCode = country.ISOTwoLetterCode,
                        Price = shippingMethod.GetShippingTotal(cart),
                        ShippingMethodName = shippingMethod.DisplayName
                    });
                }
            }
        }
Ejemplo n.º 4
0
 public CartModel Assign(CartModel cart, Guid userGuid)
 {
     cart.ShippingAddress = _getShippingAddress.Get(userGuid);
     if (cart.RequiresShipping)
     {
         cart.PotentiallyAvailableShippingMethods =
             _shippingMethodUIService.GetEnabledMethods().FindAll(method => method.CanPotentiallyBeUsed(cart));
         cart.RequestedShippingDate =
             _cartSessionManager.GetSessionValue <DateTime?>(CartManager.CurrentShippingDateKey, userGuid);
         cart.ShippingMethod = GetShippingMethod(cart, userGuid);
     }
     return(cart);
 }
Ejemplo n.º 5
0
        public List <SelectListItem> GetShippingMethodOptions()
        {
            var orderedEnumerable = _shippingMethodUIService.GetEnabledMethods().FindAll(method => method.CanBeUsed(Cart))
                                    .OrderBy(method => method.GetShippingTotal(Cart));

            if (orderedEnumerable.Any())
            {
                return(orderedEnumerable
                       .BuildSelectItemList(
                           method =>
                           string.Format("{0} ({1})", method.DisplayName,
                                         method.GetShippingTotal(Cart).ToCurrencyFormat()), method => method.TypeName,
                           method => method == _cart.ShippingMethod, "Please select..."));
            }
            return(new List <SelectListItem>());
        }