public ShippingMethodCollection GetShippingMethods(ShippingCalculationContext context) { return(new ShippingMethodCollection(new[] { new ShippingMethod { Name = string.Format(AppLogic.GetString("checkoutshipping.aspx.7", context.Customer.LocaleSetting), string.Empty), } })); }
public ShippingMethodCollection GetShippingMethods(ShippingCalculationContext context) { return(new ShippingMethodCollection(new[] { new ShippingMethod { Name = string.Format("All Orders Have Free {0} Shipping", string.Empty), } })); }
public ShippingCalculationContext( ShippingCalculationContext source, Customer customer = null, Address shippingAddress = null, CartItemCollection cartItems = null, decimal?taxRate = null, bool?shippingIsFreeIfIncludedInFreeList = null, decimal?handlingExtraFee = null, bool?excludeZeroFreightCosts = null, int?storeId = null, decimal?weight = null, CartSubtotalDelegate cartSubtotal = null) { Customer = customer ?? source.Customer; ShippingAddress = shippingAddress ?? source.ShippingAddress; CartItems = cartItems ?? source.CartItems; TaxRate = taxRate ?? source.TaxRate; ShippingIsFreeIfIncludedInFreeList = shippingIsFreeIfIncludedInFreeList ?? source.ShippingIsFreeIfIncludedInFreeList; HandlingExtraFee = handlingExtraFee ?? source.HandlingExtraFee; ExcludeZeroFreightCosts = excludeZeroFreightCosts ?? source.ExcludeZeroFreightCosts; StoreId = storeId ?? source.StoreId; Weight = weight ?? source.Weight; CartSubtotal = cartSubtotal ?? source.CartSubtotal; }
public ShippingMethodCollection GetShippingMethods(Customer customer, Address address, CartItemCollection cartItems, int storeId) { if (!cartItems.Any()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllDownloadComponents()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllSystemComponents()) { return(new ShippingMethodCollection()); } if (cartItems.NoShippingRequiredComponents()) { return(new ShippingMethodCollection()); } if (cartItems.IsAllEmailGiftCards()) { return(new ShippingMethodCollection()); } if (!AppLogic.AppConfigBool("FreeShippingAllowsRateSelection") && cartItems.IsAllFreeShippingComponents()) { return(new ShippingMethodCollection()); } var shippingCalculation = AspDotNetStorefrontCore.Shipping.GetActiveShippingCalculation(); if (shippingCalculation == null) { return(new ShippingMethodCollection()); } var returnInStorePickupRate = (shippingCalculation.GetType() == typeof(UseRealTimeRatesShippingCalculation)) && //In-Store Pickup is only allowed with realtime rates AppLogic.AppConfigBool("RTShipping.AllowLocalPickup"); var appliedStoreId = AppLogic.GlobalConfigBool("AllowShippingFiltering") ? storeId : AspDotNetStorefrontCore.Shipping.DONT_FILTER_PER_STORE; var cart = cartItems.First().ThisShoppingCart; var shippingCalculationContext = new ShippingCalculationContext( customer: customer, cartItems: cartItems, shippingAddress: address, taxRate: cart.VatIsInclusive ? customer.TaxRate(AppLogic.AppConfigUSInt("ShippingTaxClassID")) / 100m : 0, excludeZeroFreightCosts: AppLogic.AppConfigBool("FilterOutShippingMethodsThatHave0Cost"), shippingIsFreeIfIncludedInFreeList: cart.ShippingIsFree, handlingExtraFee: AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee"), storeId: appliedStoreId, weight: cart.WeightTotal(), cartSubtotal: cart.SubTotal); var availableShippingMethods = shippingCalculation.GetShippingMethods(shippingCalculationContext); if (returnInStorePickupRate && LocalPickupAvailable(address)) { availableShippingMethods.Add(new ShippingMethod { Name = "In-Store Pickup", Freight = AppLogic.AppConfigNativeDecimal("RTShipping.LocalPickupCost"), ShippingIsFree = AppLogic.AppConfigNativeDecimal("RTShipping.LocalPickupCost") == 0, }); } if (!availableShippingMethods.Any() && appliedStoreId != AspDotNetStorefrontCore.Shipping.DONT_FILTER_PER_STORE) { // no shipping methods found, let's try and fallback to the default store // (if we're not already in it) // when we're on a multi-store scenario var stores = Store.GetStoreList(); var defaultStore = Store.GetDefaultStore(); if (stores.Count > 1 && defaultStore != null && defaultStore.StoreID != appliedStoreId) { availableShippingMethods = shippingCalculation.GetShippingMethods(new ShippingCalculationContext( source: shippingCalculationContext, storeId: defaultStore.StoreID)); } // log if we still didn't find any shipping methods if (!availableShippingMethods.Any()) { var message = string.Format("No Shipping method found for StoreId: {0}", appliedStoreId); var logDetails = customer.IsRegistered ? string.Format(@" StoreId: {0} CalculationMode: {1} CustomerId: {2} Address: {3}" , appliedStoreId, AspDotNetStorefrontCore.Shipping.GetActiveShippingCalculationID(), customer.CustomerID, address.DisplayHTML(true)) : string.Empty; SysLog.LogMessage(message, logDetails, MessageTypeEnum.Informational, MessageSeverityEnum.Alert); } } //Filter out non-free shipping methods if necessary if (cart.ShippingIsFree && !AppLogic.AppConfigBool("FreeShippingAllowsRateSelection")) { var freeShippingMethodIds = AppLogic.AppConfig("ShippingMethodIDIfFreeShippingIsOn").ParseAsDelimitedList <int>(); if (freeShippingMethodIds.Any()) { availableShippingMethods.RemoveAll(sm => !freeShippingMethodIds.Contains(sm.Id)); } } //Apply shipping promotion discounts if any var shippingDiscounts = cart.DiscountResults.SelectMany(p => p.Promotion.PromotionDiscounts.OfType <Promotions.ShippingPromotionDiscount>()); if (shippingDiscounts.Any()) { foreach (var shippingMethod in availableShippingMethods) { ApplyShippingPromotion(shippingMethod, shippingDiscounts); } } return(availableShippingMethods); }