Shipping cost by Country & Total Order Weight

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 anos atrás
I need to calculate the shipping cost by Country & Total Order Weight.

eg. USA (Normal Shipping type):
70$ for first kg and
30$/kg from 2-5 kg
25$/kg more than 5 kg

(Express Shipping type 4 Days Maximum):
100$ for first kg and
60$/kg from 2-5 kg
45$/kg more than 5 kg

this algorithm for USA only and every country have a different costs.

Can I manage this algorithm using nopCommerce?
15 anos atrás
Yes. You can do it. To add new shipping rate computation methods you should implement IShippingRateComputationMethod interface.

P.S. See ShippingByTotalComputationMethod.cs and ShippingByWeightComputationMethod.cs
15 anos atrás
When I tried to use the Shipping Rate Computation Methods > Shipping By Order Weight and for example:

My Method from 0 to 1 = 40
My Method  from 1 to 2 = 20
My Method  from 2 to 10000  = 15

and if my order weight was 1.xx kg for example. I guess that the shipping cost should be 40+20 = 60
but its calculated to 20 only

advice please
15 anos atrás
That's right!

If your order weight is from 0kg to 1kg then the shipping cost should be 40
If your order weight is from 1kg to 2kg then the shipping cost should be 20
If your order weight is from 2kg to 10000kg then the shipping cost should be 15

No summary operations
15 anos atrás
it should be make a summary operations.
let one of my orders have a weight = 8 kgs
and if there is no summary operations: the shipping for previous order will be 15$

but I will pay
40$ [1st kg]+
20$ [2nd kg]+
15$*6 [to complete the 8 kgs]

and that will be 150$ !!!!!!
15 anos atrás
You're right. We'll rewrite shipping rate computation login in the next release.  Something similar to UPS (http://www.ups.com/media/en/AF_Zones_Rates_Exp_US.pdf)

We'll be using multiply operations(not summary). If your orders has a weight 8 kgs, then you'll pay 8*15$=120$
15 anos atrás
If you don't want to wait for a next release, open ShippingByWeightComputationMethod.cs from Nop.Shipping.ShippingByWeight class library and replce the code with this one:

   public class ShippingByWeightComputationMethod : IShippingRateComputationMethod
    {
        #region Methods
        /// <summary>
        /// Gets shipping rate by order total weight
        /// </summary>
        /// <param name="Cart">Current shopping cart</param>
        /// <param name="shippingInfo">Shipping info required for shipping computation</param>
        /// <param name="includeDiscounts">A value indicating whether include discounts or not for shipping computation</param>
        /// <param name="CountryFrom">Shipped from country</param>
        /// <param name="StateProvinceFrom">Shipped from state/province</param>
        /// <param name="ZipPostalCodeFrom">Shipped from zip/postal code</param>
        /// <returns>Shipping rate value;Null if shipping rate couldn't be calculated now</returns>
        public decimal? GetShippingRate(ShoppingCartCollection Cart, ShippingInfo shippingInfo, bool includeDiscounts, Country CountryFrom, StateProvince StateProvinceFrom, string ZipPostalCodeFrom)
        {
            decimal shippingTotal = decimal.Zero;

            if (shippingInfo == null)
                return null;
            if (shippingInfo.ShippingMethod == null)
                return null;

            decimal subTotal = decimal.Zero;
            foreach (ShoppingCart shoppingCartItem in Cart)
            {
                if (shoppingCartItem.IsFreeShipping || !shoppingCartItem.IsShipEnabled)
                    continue;
                if (includeDiscounts)
                    subTotal += shoppingCartItem.SubTotalWithDiscount;
                else
                    subTotal += shoppingCartItem.SubTotalWithoutDiscount;
            }

            decimal orderWeight = ShoppingCartManager.GetShoppingCartTotalWeigth(Cart);
            ShippingByWeight shippingByWeight = null;
            ShippingByWeightCollection shippingByWeightCollection = ShippingByWeightManager.GetAllByShippingMethodID(shippingInfo.ShippingMethod.ShippingMethodID);
            foreach (ShippingByWeight shippingByWeight2 in shippingByWeightCollection)
            {
                if ((orderWeight >= shippingByWeight2.From) && (orderWeight <= shippingByWeight2.To))
                {
                    shippingByWeight = shippingByWeight2;
                    break;
                }
            }
            if (shippingByWeight == null)
                return decimal.Zero;
            if (shippingByWeight.UsePercentage && shippingByWeight.ShippingChargePercentage <= decimal.Zero)
                return decimal.Zero;
            if (!shippingByWeight.UsePercentage && shippingByWeight.ShippingChargeAmount <= decimal.Zero)
                return decimal.Zero;
            if (shippingByWeight.UsePercentage)
                shippingTotal = Math.Round((decimal)((((float)subTotal) * ((float)shippingByWeight.ShippingChargePercentage)) / 100f), 2);
            else
                shippingTotal = shippingByWeight.ShippingChargeAmount * orderWeight;

            if (shippingTotal < decimal.Zero)
                shippingTotal = decimal.Zero;
            return shippingTotal;
        }
        #endregion
    }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.