public ShippingMethodCollection GetShippingMethods(ShippingCalculationContext context)
        {
            var methods = GetRates(new RealTimeRateCalculationContext(
                                       shipmentAddress: context.ShippingAddress,
                                       shippingHandlingExtraFee: AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee"),
                                       cartItems: context.CartItems,
                                       shipmentValue: context.CartSubtotal(
                                           true,   // includeDiscount
                                           false,  // onlyIncludeTaxableItems
                                           false,  // includeDownloadItems
                                           true,   // includeFreeShippingItems
                                           false,  // includeSystemItems
                                           false,  // useCustomerCurrencySetting
                                           0,      // forShippingAddressId
                                           true,   // excludeTax
                                           false)  // includeShippingNotRequiredItems
                                       ,
                                       shippingTaxRate: context.TaxRate,
                                       customerId: context.Customer.CustomerID));

            var availableShippingMethods = new ShippingMethodCollection();

            if (methods.Any())
            {
                availableShippingMethods.AddRange(GetRealTimeShippingMethods(context, methods));
            }
            else if (methods.ErrorMsg.Contains(AppLogic.AppConfig("RTShipping.CallForShippingPrompt")))
            {
                availableShippingMethods.AddRange(GetCallForShippingMethods());
            }

            return(availableShippingMethods);
        }
Пример #2
0
        public override ShippingMethodCollection GetShippingMethods(int storeId)
        {
            ShippingMethodCollection availableShippingMethods = new ShippingMethodCollection();

            decimal extraFee = AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee");

            string shipsql = GenerateShippingMethodsQuery(storeId, true);

            ShoppingCart weight = new ShoppingCart(1, ThisCustomer, CartTypeEnum.ShoppingCart, 0, false);
            decimal      SubTotalWithoutDownload = this.Cart.SubTotal(true, false, false, true, true, false, 0, true);

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader reader = DB.GetRS(shipsql.ToString(), dbconn))
                {
                    while (reader.Read())
                    {
                        ShippingMethod thisMethod = new ShippingMethod();
                        thisMethod.Id     = DB.RSFieldInt(reader, "ShippingMethodID");
                        thisMethod.Name   = DB.RSFieldByLocale(reader, "Name", ThisCustomer.LocaleSetting);
                        thisMethod.IsFree = this.ShippingIsFreeIfIncludedInFreeList && Shipping.ShippingMethodIsInFreeList(thisMethod.Id);

                        if (thisMethod.IsFree)
                        {
                            thisMethod.ShippingIsFree = true;
                            thisMethod.Freight        = decimal.Zero;
                        }
                        else
                        {
                            int     ZoneID  = Shipping.ZoneLookup(this.ShippingAddress.Zip);
                            decimal freight = Shipping.GetShipByTotalAndZoneCharge(thisMethod.Id, SubTotalWithoutDownload, ZoneID); // exclude download items!

                            if (extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            else if (freight > System.Decimal.Zero && extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            if (freight < 0)
                            {
                                freight = 0;
                            }
                            thisMethod.Freight = freight;
                        }

                        bool include = !(this.ExcludeZeroFreightCosts == true && (thisMethod.Freight == decimal.Zero && !thisMethod.IsFree));

                        if (include)
                        {
                            availableShippingMethods.Add(thisMethod);
                        }
                    }
                }
            }

            return(availableShippingMethods);
        }
        /// <summary>
        /// Set the info regarding Use Real time rates in a collection
        /// </summary>
        /// <returns>Return a collection of shipping method for  UseRealtimerates based in the computation of Use Real time rates</returns>
        public override ShippingMethodCollection GetShippingMethods(int storeId)
        {
            ShippingMethodCollection availableShippingMethods = new ShippingMethodCollection();
            ShippingMethods          s_methods = this.Cart.GetRates(this.ShippingAddress, AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee"));

            int Count = 0;

            if (s_methods.Count > 0)
            {
                foreach (ShipMethod s_method in s_methods)
                {
                    Count++;
                    ShippingMethod realTimeMethod = (ShippingMethod)s_method;
                    realTimeMethod.IsFree    &= this.ShippingIsFreeIfIncludedInFreeList;
                    realTimeMethod.IsRealTime = true;

                    if (Cart.ShippingIsFree)
                    {
                        string FreeShippingMethodIDs = Shipping.GetFreeShippingMethodIDs();

                        if (CommonLogic.IntegerIsInIntegerList(realTimeMethod.Id, FreeShippingMethodIDs))
                        {
                            realTimeMethod.Freight        = 0.0M;
                            realTimeMethod.ShippingIsFree = true;
                        }
                    }

                    bool include = !(this.ExcludeZeroFreightCosts == true && realTimeMethod.Freight == decimal.Zero);

                    if (include)
                    {
                        availableShippingMethods.Add(realTimeMethod);
                        // add it to the db
                        if (DB.GetSqlN("select count(*) as N from ShippingMethod  with (NOLOCK)  where IsRTShipping=1 and convert(nvarchar(4000),Name)=" + DB.SQuote(realTimeMethod.Name)) == 0)
                        {
                            DB.ExecuteSQL(String.Format("insert ShippingMethod(Name,IsRTShipping) values({0},1)", DB.SQuote(realTimeMethod.Name)));
                        }
                    }
                }
            }
            else if (s_methods.ErrorMsg.IndexOf(AppLogic.AppConfig("RTShipping.CallForShippingPrompt")) != -1)
            {
                ShippingMethod onlyCallForPromptShippingMethod = new ShippingMethod();
                onlyCallForPromptShippingMethod.Name       = AppLogic.AppConfig("RTShipping.CallForShippingPrompt");
                onlyCallForPromptShippingMethod.IsRealTime = true;
                onlyCallForPromptShippingMethod.Id         = -1;
                availableShippingMethods.Add(onlyCallForPromptShippingMethod);
            }
            else
            {
                ShippingMethod noShippingMethodFound = new ShippingMethod();
                noShippingMethodFound.Name       = AppLogic.GetString("checkoutshipping.estimator.control.InvalidAddress", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                noShippingMethodFound.IsRealTime = true;
                noShippingMethodFound.Id         = -2;
                availableShippingMethods.Add(noShippingMethodFound);
            }

            return(availableShippingMethods);
        }
Пример #4
0
        /// <summary>
        /// Summary for AllOrdersHaveFreeShipping
        /// </summary>
        /// <returns>Return FREE SHIPPING  as freight name in a collection</returns>
        public override ShippingMethodCollection GetShippingMethods(int storeId)
        {
            ShippingMethodCollection availableShippingMethods = new ShippingMethodCollection();
            ShippingMethod           thisMethod = new ShippingMethod();

            thisMethod.Name = "FREE SHIPPING (All Orders Have Free Shipping)";
            availableShippingMethods.Add(thisMethod);
            return(availableShippingMethods);
        }
Пример #5
0
        public ShippingMethodCollection GetShippingMethods(ShippingCalculationContext context)
        {
            var availableShippingMethods = new ShippingMethodCollection();
            var shipSql = GenerateShippingMethodsQuery(context, UsesZones);

            using (var connection = new SqlConnection(DB.GetDBConn()))
            {
                connection.Open();
                using (var reader = DB.GetRS(shipSql, connection))
                    while (reader.Read())
                    {
                        var thisMethod = new ShippingMethod
                        {
                            Id            = DB.RSFieldInt(reader, "ShippingMethodID"),
                            Name          = DB.RSFieldByLocale(reader, "Name", context.Customer.LocaleSetting),
                            IsFree        = context.ShippingIsFreeIfIncludedInFreeList && Shipping.ShippingMethodIsInFreeList(DB.RSFieldInt(reader, "ShippingMethodID")),
                            ImageFileName = DB.RSField(reader, "ImageFileName"),
                        };

                        if (thisMethod.IsFree)
                        {
                            thisMethod.ShippingIsFree = true;
                            thisMethod.Freight        = 0m;
                        }
                        else
                        {
                            var freight = CalculateFreight(context, thisMethod.Id, reader);

                            if (freight > 0m && context.HandlingExtraFee > 0m)
                            {
                                freight += context.HandlingExtraFee;
                            }

                            if (freight < 0)
                            {
                                freight = 0;
                            }

                            thisMethod.Freight = freight;
                        }

                        if (!(context.ExcludeZeroFreightCosts == true && (thisMethod.Freight == 0m && !thisMethod.IsFree)))
                        {
                            availableShippingMethods.Add(thisMethod);
                        }
                    }
            }

            return(availableShippingMethods);
        }
Пример #6
0
        /// <summary>
        /// Summary for calculation ShippingByTotalByPercent
        /// </summary>
        /// <returns>Return a collection of ShippingMethod based on the computation of ShippingByTotalByPercent</returns>
        public override ShippingMethodCollection GetShippingMethods(int storeId)
        {
            ShippingMethodCollection availableShippingMethods = new ShippingMethodCollection();

            bool shippingMethodToStateMapIsEmpty   = Shipping.ShippingMethodToStateMapIsEmpty();
            bool shippingMethodToCountryMapIsEmpty = Shipping.ShippingMethodToCountryMapIsEmpty();

            decimal extraFee = AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee");

            string shipsql = GenerateShippingMethodsQuery(storeId, false);
            //shipsql.Append("select * from ShippingMethod  with (NOLOCK)  where IsRTShipping=0 ");

            //if (!shippingMethodToStateMapIsEmpty && !ThisCustomer.IsRegistered)
            //{
            //    shipsql.Append(" and ShippingMethodID in (select ShippingMethodID from ShippingMethodToStateMap  with (NOLOCK))");
            //}

            //if (!shippingMethodToStateMapIsEmpty && ThisCustomer.IsRegistered)
            //{
            //    shipsql.Append(" and ShippingMethodID in (select ShippingMethodID from ShippingMethodToStateMap  with (NOLOCK)  where StateID=" + AppLogic.GetStateID(this.ShippingAddress.State).ToString() + ")");
            //}

            //if (!shippingMethodToCountryMapIsEmpty)
            //{
            //    shipsql.Append(" and ShippingMethodID in (select ShippingMethodID from ShippingMethodToCountryMap  with (NOLOCK)  where CountryID=" + AppLogic.GetCountryID(this.ShippingAddress.Country).ToString() + ")");
            //}
            //shipsql.Append(" order by Displayorder");

            decimal SubTotalWithoutDownload = this.Cart.SubTotal(true, false, false, true, true, false, 0, true);

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader reader = DB.GetRS(shipsql.ToString(), dbconn))
                {
                    while (reader.Read())
                    {
                        ShippingMethod thisMethod = new ShippingMethod();
                        thisMethod.Id     = DB.RSFieldInt(reader, "ShippingMethodID");
                        thisMethod.Name   = DB.RSFieldByLocale(reader, "Name", ThisCustomer.LocaleSetting);
                        thisMethod.IsFree = this.ShippingIsFreeIfIncludedInFreeList && Shipping.ShippingMethodIsInFreeList(thisMethod.Id);

                        if (thisMethod.IsFree)
                        {
                            thisMethod.Freight        = decimal.Zero;
                            thisMethod.ShippingIsFree = true;
                        }
                        else
                        {
                            decimal freight = Shipping.GetShipByTotalByPercentCharge(thisMethod.Id, SubTotalWithoutDownload); // exclude download items!

                            if (extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            else if (freight > System.Decimal.Zero && extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            if (freight < 0)
                            {
                                freight = 0;
                            }
                            thisMethod.Freight = freight;
                        }

                        bool include = !(this.ExcludeZeroFreightCosts == true && (thisMethod.Freight == decimal.Zero && !thisMethod.IsFree));

                        if (include)
                        {
                            availableShippingMethods.Add(thisMethod);
                        }
                    }
                }
            }


            return(availableShippingMethods);
        }
        /// <summary>
        /// Represent the calculation for ShippingByTotal
        /// </summary>
        /// <returns>return collection of shipping method based on the computation of ShippingByTotalByPercent</returns>
        public override ShippingMethodCollection GetShippingMethods(int storeId)
        {
            ShippingMethodCollection availableShippingMethods = new ShippingMethodCollection();

            bool shippingMethodToStateMapIsEmpty   = Shipping.ShippingMethodToStateMapIsEmpty();
            bool shippingMethodToCountryMapIsEmpty = Shipping.ShippingMethodToCountryMapIsEmpty();

            decimal extraFee = AppLogic.AppConfigUSDecimal("ShippingHandlingExtraFee");

            string shipsql = GenerateShippingMethodsQuery(storeId, false);

            decimal SubTotalWithoutDownload = this.Cart.SubTotal(true, false, false, false, true, false, 0, true);

            using (SqlConnection dbconn = new SqlConnection(DB.GetDBConn()))
            {
                dbconn.Open();
                using (IDataReader reader = DB.GetRS(shipsql.ToString(), dbconn))
                {
                    while (reader.Read())
                    {
                        ShippingMethod thisMethod = new ShippingMethod();
                        thisMethod.Id     = DB.RSFieldInt(reader, "ShippingMethodID");
                        thisMethod.Name   = DB.RSFieldByLocale(reader, "Name", ThisCustomer.LocaleSetting);
                        thisMethod.IsFree = this.ShippingIsFreeIfIncludedInFreeList && Shipping.ShippingMethodIsInFreeList(thisMethod.Id);

                        if (Cart.ShippingIsFree)
                        {
                            string FreeShippingMethodIDs = Shipping.GetFreeShippingMethodIDs();

                            if (CommonLogic.IntegerIsInIntegerList(thisMethod.Id, FreeShippingMethodIDs))
                            {
                                thisMethod.Freight        = 0.0M;
                                thisMethod.ShippingIsFree = true;
                            }
                        }

                        if (thisMethod.IsFree)
                        {
                            thisMethod.Freight = decimal.Zero;
                        }
                        else
                        {
                            decimal freight = Shipping.GetShipByTotalCharge(thisMethod.Id, SubTotalWithoutDownload); // exclude download items!


                            if (extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            else if (freight > System.Decimal.Zero && extraFee > System.Decimal.Zero)
                            {
                                freight += extraFee;
                            }
                            if (freight < 0)
                            {
                                freight = 0;
                            }
                            thisMethod.Freight = freight;
                        }

                        bool include = !(this.ExcludeZeroFreightCosts == true && (thisMethod.Freight == decimal.Zero && !thisMethod.IsFree));

                        if (include)
                        {
                            availableShippingMethods.Add(thisMethod);
                        }
                    }
                }
            }

            return(availableShippingMethods);
        }