Skip to end of metadata
Go to start of metadata

If customers have some shippable products, they can choose a shipping option during checkout. These shipping options are returned from shipping rate computation methods (such as UPS, USPS, FedEx, etc). Shipping rate computation methods are implemented as plugins in nopCommerce. We recommend you read How to write a nopCommerce plugin before you start coding a new shipping rate computation method. The article will explain to you the required steps for creating a plugin. So actually a shipping rate computation method is an ordinary plugin which implements an IShippingRateComputationMethod interface (Nop.Services.Shipping namespace). So add a new shipping plugin project (class library) to solution and let's get started.

Controllers, views, models.

Add a controller and an appropriate Configure action method and a view. These will define how a store owner sees configuration options in admin panel (System > Configuration > Shipping > Shipping rate computation methods). This article does not explain how to configure plugins, but you can find more info about it here.

How to code my own shipping rate computation method

Once this step is complete, you can start adding required business logic for getting shipping options.

Getting shipping options.

Now you need to create a class which implements IShippingRateComputationMethod interface. This is the class that will be doing all the actual work. When nopCommerce calculates shipping totals or needs to get a list of available shipping options, the GetShippingOptions or GetFixedRate methods of your class will be called. Here is how UPSComputationMethod class is defined (“UPS” method):

    /// UPS computation method     
    public class UPSComputationMethod : BasePlugin, IShippingRateComputationMethod

IShippingRateComputationMethod interface has several methods and properties which are required to implement.

    • ShippingRateComputationMethodType. This property indicates how your shipping rate computation works. It can be Offline or RealtimeOffline plugins do not use any third-party sites to get the rates (examples of such methods are “Shipping by weight” and “Fixed Rate Shipping”). These plugins get all the required information from local databases. Realtime plugins use third-party sites to get the rates (for example, UPS or USPS).
    • GetShippingOptions. This method is always invoked when a customer chooses a shipping option during checkout. What you have do in this method is to return a list of ShippingOption objects. Each ShippingOption object contains information about certain shipping options such as option name (for example, “By ground”) and its rate (for example, 10 USD). Put all your logic here (get the rates from your database or requests them from a third-party site such as UPS).
    • GetFixedRate. As you already know GetShippingOptions is used to get shipping options during checkout (on “Select shipping method” page). But sometimes we need to know a shipping rate before a shipping option is chosen (for example, on shopping cart page). In this case you can return a fixed rate. For example, your shipping rate computation method provides only one shipping option, and there’s no need to wait until the customer chooses it on “Select shipping method” page. Return will be null, if your fixed rates are not supported. In this case customers will see the following message beside “Shipping total” on the shopping cart: “Calculated during checkout”.
    • GetConfigurationRoute. As you remember we created a controller in the previous step. This method should return a route information of its Configure method. For example,
      public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
                  actionName = "Configure";
                  controllerName = "ShippingUPS";
                  routeValues = new RouteValueDictionary() { { "Namespaces", "Nop.Plugin.Shipping.UPS.Controllers" }, { "area", null } };


Hopefully this will get you started with adding a new shipping rate computation method.

  • No labels