public void ShippingShouldBeFreeWhenAllShoppingCartItemsAreMarkedAsFreeShipping() { var product = _productService.GetProductBySku("FR_451_RB"); product.IsFreeShipping = true; _productService.UpdateProduct(product); _productService.GetProductBySku("FIRST_PRP"); product.IsFreeShipping = true; _productService.UpdateProduct(product); _orderTotalCalcService.IsFreeShipping(ShoppingCart).Should().BeTrue(); }
public void Shipping_should_be_free_when_all_shoppingCartItems_are_marked_as_freeShipping() { var product1 = new Product { Weight = 1.5M, Height = 2.5M, Length = 3.5M, Width = 4.5M, IsFreeShipping = true, IsShipEnabled = true }; _productService.InsertProduct(product1); var sci1 = new ShoppingCartItem { AttributesXml = string.Empty, Quantity = 3, ProductId = product1.Id }; var product2 = new Product { Weight = 11.5M, Height = 12.5M, Length = 13.5M, Width = 14.5M, IsFreeShipping = true, IsShipEnabled = true }; _productService.InsertProduct(product2); var sci2 = new ShoppingCartItem { AttributesXml = string.Empty, Quantity = 4, ProductId = product2.Id }; var cart = new List <ShoppingCartItem> { sci1, sci2 }; var customer = _customerService.GetCustomerById(1); cart.ForEach(sci => sci.CustomerId = customer.Id); _orderTotalCalcService.IsFreeShipping(cart).Should().BeTrue(); }
/// <summary> /// Prepares the checkout pickup points model /// </summary> /// <param name="cart">Cart</param> /// <returns>The checkout pickup points model</returns> protected virtual CheckoutPickupPointsModel PrepareCheckoutPickupPointsModel(IList <ShoppingCartItem> cart) { var model = new CheckoutPickupPointsModel() { AllowPickupInStore = _shippingSettings.AllowPickupInStore }; if (model.AllowPickupInStore) { model.DisplayPickupPointsOnMap = _shippingSettings.DisplayPickupPointsOnMap; model.GoogleMapsApiKey = _shippingSettings.GoogleMapsApiKey; var pickupPointProviders = _pickupPluginManager.LoadActivePlugins(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id); if (pickupPointProviders.Any()) { var languageId = _workContext.WorkingLanguage.Id; var pickupPointsResponse = _shippingService.GetPickupPoints(_workContext.CurrentCustomer.BillingAddressId ?? 0, _workContext.CurrentCustomer, storeId: _storeContext.CurrentStore.Id); if (pickupPointsResponse.Success) { model.PickupPoints = pickupPointsResponse.PickupPoints.Select(point => { var country = _countryService.GetCountryByTwoLetterIsoCode(point.CountryCode); var state = _stateProvinceService.GetStateProvinceByAbbreviation(point.StateAbbreviation, country?.Id); var pickupPointModel = new CheckoutPickupPointModel { Id = point.Id, Name = point.Name, Description = point.Description, ProviderSystemName = point.ProviderSystemName, Address = point.Address, City = point.City, County = point.County, StateName = state != null ? _localizationService.GetLocalized(state, x => x.Name, languageId) : string.Empty, CountryName = country != null ? _localizationService.GetLocalized(country, x => x.Name, languageId) : string.Empty, ZipPostalCode = point.ZipPostalCode, Latitude = point.Latitude, Longitude = point.Longitude, OpeningHours = point.OpeningHours }; var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentCustomer, ShoppingCartType.ShoppingCart, _storeContext.CurrentStore.Id); var amount = _orderTotalCalculationService.IsFreeShipping(cart) ? 0 : point.PickupFee; if (amount > 0) { amount = _taxService.GetShippingPrice(amount, _workContext.CurrentCustomer); amount = _currencyService.ConvertFromPrimaryStoreCurrency(amount, _workContext.WorkingCurrency); pickupPointModel.PickupFee = _priceFormatter.FormatShippingPrice(amount, true); } //adjust rate var shippingTotal = _orderTotalCalculationService.AdjustShippingRate(point.PickupFee, cart, out var _, true); var rateBase = _taxService.GetShippingPrice(shippingTotal, _workContext.CurrentCustomer); var rate = _currencyService.ConvertFromPrimaryStoreCurrency(rateBase, _workContext.WorkingCurrency); pickupPointModel.PickupFee = _priceFormatter.FormatShippingPrice(rate, true); return(pickupPointModel); }).ToList(); } else { foreach (var error in pickupPointsResponse.Errors) { model.Warnings.Add(error); } } } //only available pickup points var shippingProviders = _shippingPluginManager.LoadActivePlugins(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id); if (!shippingProviders.Any()) { if (!pickupPointProviders.Any()) { model.Warnings.Add(_localizationService.GetResource("Checkout.ShippingIsNotAllowed")); model.Warnings.Add(_localizationService.GetResource("Checkout.PickupPoints.NotAvailable")); } model.PickupInStoreOnly = true; model.PickupInStore = true; return(model); } } return(model); }