Esempio n. 1
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
                    });
                }
            }
        }
        public void MoreThanOneMethodWithSameSizeWorks()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultDomesticShippingMethod      = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var defaultInternationalShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 10);
            var largeDomesticShippingMethod        = ShippingHelpers.BuildSizeBasedShippingMethod(price: 5, size: "L", priority: 1);
            var largeInternationalShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 15, size: "L", priority: 1);
            var methods = new IShippingMethod[] {
                defaultDomesticShippingMethod,
                defaultInternationalShippingMethod,
                largeDomesticShippingMethod,
                largeInternationalShippingMethod
            };

            Assert.IsFalse(defaultDomesticShippingMethod.ComputePrice(cart, methods, null, null, null).Any());
            Assert.IsFalse(defaultInternationalShippingMethod.ComputePrice(cart, methods, null, null, null).Any());
            Assert.AreEqual(5, largeDomesticShippingMethod.ComputePrice(cart, methods, null, null, null).First().Price);
            Assert.AreEqual(15, largeInternationalShippingMethod.ComputePrice(cart, methods, null, null, null).First().Price);
        }
 private string GetConfigureUrl(IShippingMethod method)
 {
     if (!string.IsNullOrWhiteSpace(method.ConfigureAction) &&
         !string.IsNullOrWhiteSpace(method.ConfigureController))
         return _urlHelper.Action(method.ConfigureAction, method.ConfigureController);
     return null;
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public void FixedShippingPriceMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    ShippingCost = 2, Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var mediumShippingMethod  = ShippingHelpers.BuildUspsShippingMethod(size: "M", priority: 1);
            var largeShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 2);
            var shippingMethods       = new IShippingMethod[]
            { defaultShippingMethod, mediumShippingMethod, largeShippingMethod };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.IsFalse(
                defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
            Assert.IsFalse(
                mediumShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
            Assert.AreEqual(7,
                            largeShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                             wca).First().Price);
        }
Esempio n. 6
0
 public static bool IsAbleToUseShippingMethod(this CartItem item, IShippingMethod shippingMethod)
 {
     var productVariant = item.Item;
     if (!productVariant.RequiresShipping)
         return true;
     return !productVariant.HasRestrictedShipping ||
            productVariant.RestrictedTo.Contains(shippingMethod.TypeName);
 }
Esempio n. 7
0
 private string GetConfigureUrl(IShippingMethod method)
 {
     if (!string.IsNullOrWhiteSpace(method.ConfigureAction) &&
         !string.IsNullOrWhiteSpace(method.ConfigureController))
     {
         return(_urlHelper.Action(method.ConfigureAction, method.ConfigureController));
     }
     return(null);
 }
 public ActionResult SetShipping(
     [IoCModelBinder(typeof(ShippingMethodModelBinder))] IShippingMethod shippingMethod)
 {
     _setShippingMethodService.SetShippingMethod(shippingMethod);
     if (Request.IsAjaxRequest())
     {
         return(Json(true));
     }
     return(_setShippingMethodService.RedirectToShippingDetails());
 }
Esempio n. 9
0
 private static decimal GetShippingCost(CustomerBase customer, IShippingMethod shippingMethod)
 {
     if (customer is PrimeCustomer)
     {
         return 0;
     }
     else
     {
         return shippingMethod.CalculatePrice();
     }
 }
Esempio n. 10
0
 public CommonService(IState state, IShippingMethod shippingMethod, ISuggestCourse suggestCourse, IEnterprise enterprise, IIndustry industry, IOrganizationContact contact, IMenu menu, IClientType cientType)
 {
     _state          = state;
     _shippingMethod = shippingMethod;
     _suggestCourse  = suggestCourse;
     _enterprise     = enterprise;
     _industry       = industry;
     _contact        = contact;
     _menu           = menu;
     _cientType      = cientType;
 }
Esempio n. 11
0
        private IShippingMethod GetShippingMethod(CartModel cart, Guid userGuid)
        {
            var             type           = _cartSessionManager.GetSessionValue <string>(CartManager.CurrentShippingMethodTypeKey, userGuid);
            IShippingMethod shippingMethod = _shippingMethodUIService.GetMethodByTypeName(type);

            if (shippingMethod != null)
            {
                return(shippingMethod.CanBeUsed(cart) ? shippingMethod : null);
            }
            return(null);
        }
Esempio n. 12
0
        public static bool IsAbleToUseShippingMethod(this CartItemData item, IShippingMethod shippingMethod)
        {
            var productVariant = item.Item;

            if (!productVariant.RequiresShipping)
            {
                return(true);
            }
            return(!productVariant.HasRestrictedShipping ||
                   productVariant.RestrictedTo.Contains(shippingMethod.TypeName));
        }
Esempio n. 13
0
 public void SetShippingMethod(IShippingMethod shippingMethod)
 {
     if (shippingMethod != null)
     {
         _cartSessionManager.SetSessionValue(CurrentShippingMethodTypeKey, _getUserGuid.UserGuid,
             shippingMethod.TypeName);
     }
     else
     {
         _cartSessionManager.RemoveValue(CurrentShippingMethodTypeKey, _getUserGuid.UserGuid);
     }
 }
Esempio n. 14
0
 public void SetShippingMethod(IShippingMethod shippingMethod)
 {
     if (shippingMethod != null)
     {
         _cartSessionManager.SetSessionValue(CurrentShippingMethodTypeKey, _getUserGuid.UserGuid,
                                             shippingMethod.TypeName);
     }
     else
     {
         _cartSessionManager.RemoveValue(CurrentShippingMethodTypeKey, _getUserGuid.UserGuid);
     }
 }
        public void LargeObjectShippingMethodSelectedIfAnyLargeObject()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub()),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var largeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "L", priority: 1);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, largeShippingMethod };

            Assert.IsFalse(defaultShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.AreEqual(3, largeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
Esempio n. 16
0
        public void MarkupMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.Markup = 4;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(7,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
        }
        public void NoShippingMethodPriceAppliedIfAllProductsHaveFixedShipping()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2, Size = "L", ShippingCost = 1
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1, ShippingCost = 3
                })
            };
            var weightShippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var sizeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var shippingMethods      = new IShippingMethod[] { weightShippingMethod, sizeShippingMethod };

            Assert.AreEqual(7, weightShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
            Assert.AreEqual(7, sizeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
        public void DefaultWeightAndSizeMethodsBothGetSelectedIfRelevant()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 2, Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 1
                })
            };
            var weightShippingMethod = ShippingHelpers.BuildWeightBasedShippingMethod(price: 3);
            var sizeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var shippingMethods      = new IShippingMethod[] { weightShippingMethod, sizeShippingMethod };

            Assert.AreEqual(3, weightShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
            Assert.AreEqual(3, sizeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
Esempio n. 19
0
        public void AboveMinimumTotalQuantityHits()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod(
                minimumQuantity: 2);
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices.Count(), Is.EqualTo(1));
        }
Esempio n. 20
0
        public void LargeObjectShippingMethodNotSelectedIfNoLargeObject()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub())
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var largeShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, largeShippingMethod };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(3,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
            Assert.IsFalse(
                largeShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca).Any());
        }
Esempio n. 21
0
        public void MoreThanMaximumDistinctQuantityMisses()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod(
                maximumQuantity: 1,
                countDistinct: true);
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices, Is.Empty);
        }
Esempio n. 22
0
        /// <summary>
        /// Check out a shopping cart
        /// </summary>
        /// <param name="purchaseItemList"></param>
        /// <param name="customer"></param>
        /// <param name="payment"></param>
        /// <param name="shippingMethod"></param>
        public static CustomerOrder Checkout(IPurchaseItemList purchaseItemList, CustomerBase customer, IPaymentMethod payment, IShippingMethod shippingMethod)
        {
            var customerOrder = new CustomerOrder();
            customerOrder.OrderDateTime = DateTime.Now;
            purchaseItemList.Items.ForEach(i => customerOrder.Items.Add(i.Clone()));
            customerOrder.Customer = customer;
            customerOrder.Status = EOrderStatus.Processing;
            customerOrder.ShippingMethod = shippingMethod.MethodName();
            customerOrder.PaymentMethod = payment.PaymentName();
            customerOrder.ProductCost = purchaseItemList.GetTotalPrice();
            customerOrder.ShippingCost = GetShippingCost(customer, shippingMethod);
            customerOrder.TotalCost = customerOrder.ProductCost + customerOrder.ShippingCost;

            payment.Charge(customerOrder.TotalCost);

            //todo : persist order

            return customerOrder;
        }
Esempio n. 23
0
        public void WithNoMaximumWeightAnythingGoes()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 30.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 20.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 10;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.AreEqual(3,
                            defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220",
                                                               wca).First().Price);
        }
Esempio n. 24
0
        public void WeightAboveMaximumWeightFails()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 1;
            defaultShippingMethod.MaximumWeightInOunces = 6.9;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.That(prices, Is.Empty);
        }
Esempio n. 25
0
        public void WeightAtMaximumWeightPasses()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Weight = 3.0 / 16
                }),                                                                    // For the moment, weight is in pounds here
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Weight = 2.0 / 16
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildUspsShippingMethod();

            defaultShippingMethod.WeightPaddingInOunces = 1;
            defaultShippingMethod.MaximumWeightInOunces = 8;
            var shippingMethods = new IShippingMethod[] { defaultShippingMethod };
            var wca             = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);
            var prices          = defaultShippingMethod.ComputePrice(cart, shippingMethods, Country.UnitedStates, "90220", wca);

            Assert.AreEqual(3, prices.First().Price);
        }
Esempio n. 26
0
 public ProductPriceEditorViewModel(
     ProductVatConfigurationPart vatPart,
     IShippingMethod shipping,
     IVatConfigurationService vatConfigurationService)
     : this(vatPart) {
     // There are two different cases here: FlexibleShippingMethodPart or the others
     HasDiscount = false;
     var rate = vatConfigurationService.GetRate(vatPart.VatConfigurationPart ?? vatConfigurationService.GetDefaultCategory());
     if (shipping is FlexibleShippingMethodPart)
     {
         ShowShape = true;
         var flexible = shipping as FlexibleShippingMethodPart;
         BasePrice       = flexible.DefaultPrice;
         BaseTaxedPrice  = Math.Round(flexible.DefaultPrice * (1.0m + rate), 2);
         OriginalPriceId = "FlexibleShippingMethodPart_DefaultPrice";
     }
     // NOTE: VAT configuration currently only works properly and is tested
     // for FlexibleShippingMethodPart. Other IShippingMethod implementations
     // likely don't work with it.
 }
        public void FixedShippingPriceMakesItIntoPrice()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    ShippingCost = 2, Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultShippingMethod = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3);
            var mediumShippingMethod  = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "M", priority: 1);
            var largeShippingMethod   = ShippingHelpers.BuildSizeBasedShippingMethod(price: 3, size: "L", priority: 2);
            var shippingMethods       = new IShippingMethod[] { defaultShippingMethod, mediumShippingMethod, largeShippingMethod };

            Assert.IsFalse(defaultShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.IsFalse(mediumShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).Any());
            Assert.AreEqual(7, largeShippingMethod.ComputePrice(cart, shippingMethods, null, null, null).First().Price);
        }
Esempio n. 28
0
        public void MoreThanOneMethodWithSameSizeWorks()
        {
            var cart = new[] {
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                }),
                new ShoppingCartQuantityProduct(2, new ProductStub {
                    Size = "M"
                }),
                new ShoppingCartQuantityProduct(1, new ProductStub {
                    Size = "L"
                })
            };
            var defaultDomesticShippingMethod      = ShippingHelpers.BuildUspsShippingMethod();
            var defaultInternationalShippingMethod = ShippingHelpers.BuildUspsShippingMethod();
            var largeDomesticShippingMethod        = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var largeInternationalShippingMethod   = ShippingHelpers.BuildUspsShippingMethod(size: "L", priority: 1);
            var methods = new IShippingMethod[] {
                defaultDomesticShippingMethod,
                defaultInternationalShippingMethod,
                largeDomesticShippingMethod,
                largeInternationalShippingMethod
            };
            var wca = ShippingHelpers.GetUspsWorkContextAccessor("foo", false, false, 3);

            Assert.IsFalse(
                defaultDomesticShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220", wca).Any());
            Assert.IsFalse(
                defaultInternationalShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220", wca)
                .Any());
            Assert.AreEqual(3,
                            largeDomesticShippingMethod.ComputePrice(cart, methods, Country.UnitedStates, "90220",
                                                                     wca).First().Price);
            Assert.AreEqual(3,
                            largeInternationalShippingMethod.ComputePrice(cart, methods, Country.UnitedStates,
                                                                          "90220", wca).First().Price);
        }
Esempio n. 29
0
 public void SetShippingMethod(IShippingMethod shippingMethod)
 {
     _cartManager.SetShippingMethod(shippingMethod);
 }
Esempio n. 30
0
 public UserOrderService(List <UserOrderItem> orders, IShippingMethod shippingMethod, IDiscountCalculator discountCalculator)
 {
     _shippingMethod     = shippingMethod;
     _orders             = orders;
     _discountCalculator = discountCalculator;
 }
Esempio n. 31
0
 public void SetShippingMethod(IShippingMethod shippingMethod)
 {
     _cartManager.SetShippingMethod(shippingMethod);
 }