示例#1
0
        /// <summary>
        /// Gets the rate for the shipping method
        /// </summary>
        /// <param name="subtotal">the order's subtotal</param>
        /// <param name="shippingMethodId">the shipping method identifier</param>
        /// <param name="countryId">country identifier</param>
        /// <param name="stateProvinceId">state province identifier</param>
        /// <param name="zip">Zip code</param>
        /// <returns>the rate for the shipping method</returns>
        private decimal?GetRate(decimal subtotal, int shippingMethodId, int storeId, int countryId, int stateProvinceId, string zip)
        {
            decimal?shippingTotal = null;

            var shippingByTotalRecord = _shippingByTotalService.FindShippingByTotalRecord(shippingMethodId, storeId, countryId, subtotal, stateProvinceId, zip);

            if (shippingByTotalRecord == null)
            {
                if (_shippingByTotalSettings.LimitMethodsToCreated)
                {
                    return(null);
                }
                else
                {
                    return(decimal.Zero);
                }
            }

            decimal baseCharge = shippingByTotalRecord.BaseCharge;
            decimal?maxCharge  = shippingByTotalRecord.MaxCharge;

            if (shippingByTotalRecord.UsePercentage && shippingByTotalRecord.ShippingChargePercentage <= decimal.Zero)
            {
                return(baseCharge); //decimal.Zero;
            }

            if (!shippingByTotalRecord.UsePercentage && shippingByTotalRecord.ShippingChargeAmount <= decimal.Zero)
            {
                return(decimal.Zero);
            }

            if (shippingByTotalRecord.UsePercentage)
            {
                shippingTotal  = Math.Round((decimal)((((float)subtotal) * ((float)shippingByTotalRecord.ShippingChargePercentage)) / 100f), 2);
                shippingTotal += baseCharge;
                if (maxCharge.HasValue && maxCharge > baseCharge)
                {
                    // shipping charge should not exceed MaxCharge
                    shippingTotal = Math.Min(shippingTotal.Value, maxCharge.Value);
                }
            }
            else
            {
                shippingTotal = shippingByTotalRecord.ShippingChargeAmount;
            }

            if (shippingTotal < decimal.Zero)
            {
                shippingTotal = decimal.Zero;
            }

            return(shippingTotal);
        }
示例#2
0
        /// <summary>
        /// Gets the rate for the shipping method
        /// </summary>
        /// <param name="subtotal">The order's subtotal</param>
        /// <param name="shippingMethodId">The shipping method identifier</param>
        /// <param name="storeId">Store identifier</param>
        /// <param name="warehouseId">Warehouse identifier</param>
        /// <param name="countryId">Country identifier</param>
        /// <param name="stateProvinceId">State / province identifier</param>
        /// <param name="zipPostalCode">ZIP / postal code</param>
        /// <returns>the rate for the shipping method</returns>
        private decimal?GetRate(decimal subtotal, int shippingMethodId, int storeId, int warehouseId, int countryId, int stateProvinceId, string zipPostalCode)
        {
            decimal?shippingTotal = null;

            var shippingByTotalRecord = _shippingByTotalService.FindShippingByTotalRecord(shippingMethodId, storeId, warehouseId, countryId, subtotal, stateProvinceId, zipPostalCode);

            if (shippingByTotalRecord == null)
            {
                if (_shippingByTotalSettings.LimitMethodsToCreated)
                {
                    return(null);
                }

                return(decimal.Zero);
            }

            if (shippingByTotalRecord.UsePercentage && shippingByTotalRecord.ShippingChargePercentage <= decimal.Zero)
            {
                return(decimal.Zero);
            }

            if (!shippingByTotalRecord.UsePercentage && shippingByTotalRecord.ShippingChargeAmount <= decimal.Zero)
            {
                return(decimal.Zero);
            }

            if (shippingByTotalRecord.UsePercentage)
            {
                shippingTotal = Math.Round((decimal)((((float)subtotal) * ((float)shippingByTotalRecord.ShippingChargePercentage)) / 100f), 2);
            }
            else
            {
                shippingTotal = shippingByTotalRecord.ShippingChargeAmount;
            }

            if (shippingTotal < decimal.Zero)
            {
                shippingTotal = decimal.Zero;
            }

            return(shippingTotal);
        }