Question about 'Shipping by Total' behaviour.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 anni tempo fa
Hi everyone,

I have installed and configured nopCommerce 1.40.

I have added a new 'Shipping Rate Computation Method' for the 'Shipping by order total' method.
It will add a shipping fee of 20.00EUR for any order that is shipped by ground and has a sub total more than 100.00EUR.

I now am wondering how this works.

I assume:
1. The ShippingManager will get the shipping total for the cart.
2. A new instance of 'IShippingRateComputationMethod' will be created, in this case a 'ShippingByTotalComputationMethod' instance.
3. The method GetFixedRate will be called to calculate the price (see note below).

However I have seen in the source code that most classes that derive from 'IShippingRateComputationMethod' simply return null. Can anyone explain how this bit of code works???

Kind Regards,
Mathijs


note: This is the file I found in the original source code:
..\nopCommerce_1.40\Shipping\Nop.Shipping.ShippingByTotal\ShippingByTotalComputationMethod.cs
13 anni tempo fa
I found that eventually the method 'ShippingByTotalComputationMethod.GetRate' is called when an order is saved to the database. That means that in the shopping cart and during the checkout process no price is calculated.

To overcome this issue I wrote a new ShippingByTotalComputationMethod class and altered the namespace.
I made a copy of the old file (..\nopCommerce_1.40\Shipping\Nop.Shipping.ShippingByTotal\ShippingByTotalComputationMethod.cs) and replaced the method GetFixedRate with this bit of code:
        public decimal? GetFixedRate(ShipmentPackage ShipmentPackage)
        {
            decimal subTotal = decimal.Zero;
            foreach (ShoppingCartItem shoppingCartItem in ShipmentPackage.Items)
            {
                if (shoppingCartItem.IsFreeShipping)
                    continue;
                subTotal += PriceHelper.GetSubTotal(shoppingCartItem, ShipmentPackage.Customer, true);
            }

            ShippingMethod defaultShippingMethod = ShippingMethodManager.GetAllShippingMethods().FirstOrDefault();
            decimal shipmentRate = GetRate(subTotal, defaultShippingMethod.ShippingMethodID);
            return shipmentRate;
        }



The class was added to a new library. The library was compiled and copied to the 'bin' folder of the NOPcommerce website.

In the administration (www\Administration\ShippingRateComputationMethods.aspx) a new shipping rate computation method was added with the following details:
NAME: Shipping by order total (Custom)
DESCRIPTION:
CONFIGURATION TEMPLATE PATH: Shipping\ShippingByTotalConfigure\ConfigureShipping.ascx
CLASS NAME: MyNameSpaceName.NopCommerce.Shipping.Methods.ShippingByTotalCM.ShippingByTotalComputationMethod, MyNameSpaceName.NopCommerce.Shipping.ShippingByTotal
DISPLAY ORDER: 5

Now my shopping cart display's the correct shipping fee based on the items and their price in the cart.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.