Loading...
Area: Episerver Commerce
Applies to versions: 10 and higher
Other versions:

Shipping gateways and providers

In Episerver Commerce, shipping gateways and providers return the appropriate shipping charge for a cart during checkout.

How it works

Two shipping gateways/providers are included by default.

  • Generic Gateway. Flat shipping rate.
  • Weight/Jurisdiction Gateway. Base price + additional fee depending on weight and shipping location.

You also can add your own shipping gateway and provider. Under Shipping Providers, a Shipping Gateway is the specific class that you select (Generic Gateway or Weight/Jurisdiction Gateway).

In this topic

Classes in this topic are available in the following namespaces:

  • Mediachase.Commerce.Orders. Contains IShippingGateway, IShippingPlugin.
  • Mediachase.Commerce.Catalog.Data. Contains CurrencyAdmin.
  • Mediachase.Commerce.Orders.Dto. Contains ShippingMethodDto.

See also Shipping Methods.

Shipping gateways

You select a Shipping Gateway on the Shipping Provider screen. Configure the values for a gateway/provider in the Shipping Methods area.

  • Shipping Jurisdictions. Lets you define values for region-specific shipping rates; only used when you select the Weight/Jurisdiction Gateway, such as California.
  • Shipping Jurisdiction Groups. Group of jurisdictions; a required field when configuring Shipping Method parameters, such as Southwest region.

Shipping providers

Shipping provider classes retrieve shipping price information from one or more shipping services, such as USPS, UPS, or FedEX. Typically, a provider represents one service, for example, USPS. A provider also can represent a type of shipping situation, for example, overnight delivery. The provider can retrieve pricing for that service to determine the lowest price for a customer location. A provider can also represent other scenarios with one or more services, such as price by weight or ground shipping.

Key classes and files

  • IShippingGateway. Interface implemented in creating a shipping gateway.
  • IShippingPlugin. The same functionality as IShippingGateway but works only with the abstraction API instead of concrete classes.
  • WeightJurisdictionGateway. Example implementation.
  • GenericGateway. Example implementation.
  • CurrencyAdmin. Provides lookup for currency codes.
  • ShippingMethodDto. DTO for shipping method configuration information.
  • JurisdictionManager. Provides methods to retrieve jurisdictions.

Note: IShippingPlugin is highly recommended. IShippingGateway still exists for supporting backward compatibility.

Creating shipping options

To provide shipping options during checkout, you need to add shipping methods, and each method must use a shipping provider. The following steps create a custom shipping provider and method.

  1. In the solution, create a separate project to store custom business logic implementations for your application.
  2. In this project, create a class  that inherits from IShippingPlugin. This interface only has one method, GetRate(). This method returns the rate for shipping associated with the IShipment from the shopping cart submitted for pricing. This method provides whatever interface is required to the actual shipping services/rate provider to determine the shipping cost.

    Example: the method's signature:

    public ShippingRate GetRate(Guid methodId, IShipment shipment, ref string message)

    The return value is a ShippingRate instance, which contains several properties:

    • Id. For the associated shipping method. This value is passed to the method (first parameter).
    • Money. The price connected to the shipping company. It should correspond to one of the currencies associated with the application.
      To retrieve currency information from the database, use the CurrencyAdmin object.
    • Name. The name of the shipping method associated with the shipping method ID.
  3. Copy the .dlls associated with the project where the shipping gateway is implemented to the bin folders of the Commerce Manager and public web sites.
  4. In Commerce Manager, go to the Admin tab.
  5. Go to Order System > Shipping Providers.
  6. Click New.
  7. Enter a name for the gateway and a system keyword. The system keyword must be unique.
  8. Select the gateway which implements IShippingGateway you created in the previous step.
  9. Click OK.
  10. Go to Order System > Shipping Methods > /[applicable language].
  11. Click New.
  12. Fill in the fields for the method, including the name of the provider created in the previous step. To make the shipping method available, set IsActive to Yes.
  13. Click OK.

Adding a configuration tab

You can create a configuration tab for your shipping method. This lets you use multiple instances of a custom shipping provider then set custom parameters for each instance. To do this, create a user control that renders in Commerce Manager as the Parameters tab for a shipping method.

The custom control creates/updates/retrieves shipping data about different circumstances based on weight, number of items, and jurisdiction that your custom shipping gateway uses to calculate shipping rate. The following steps show how to create a configuration tab.

  1. Add a new control to your custom shipping provider project. Call the control ConfigureShippingMethod.ascx.
  2. Make sure the new control inherits from OrderBaseUserControl and implements the IGatewayControl interface.
  3. Add references to your project for Mediachase.Commerce.dll and Mediachase.Webconsolelib.dll.
  4. The IGatewayControl interface has two methods and a required property.

    These two methods are called by Commerce Manager. The DTO object passed to both methods is, in the case of a shipping provider configuration tab, an instance of a ShippingMethodDto.cs. This DTO contains a table, ShippingMethodCase, which holds all shipping rate scenarios that you store for the shipping method.

    The code in the control simply needs to update the ShippingMethodCase rows to reflect each scenario the user adds in Commerce Manager. Commerce Manager takes care of retrieving the data and saving the data back to the database.

    Each shipping scenario is a row of data. The framework provides this scenario storage for your implementation. In other words, the scenario data you store for a shipping method in the ShippingMethodCase table is not used by the framework during the checkout.

    Each row of data include these fields:

    • Total. A number which can represent weight, item count, or another number indicator.
    • Charge. Represents the cost.
    • StartDate, EndDate. Lets you specify the date range of the rate validity.
    • JurisdictionGroupId. Maps to a jurisdiction group configured in the Jursidictions/Jurisdiction Groups section of Commerce Manager.
    • ShippingMethodId. The ID for the shipping method.

    You can retrieve jurisdiction groups using the JurisdictionManager.

  5. Implement the SaveChanges() and LoadObject() methods.

    Example: minimum code for SaveChanges() and LoadObject() methods

    _shippingMethodDto = dto as ShippingMethodDto;

    The _ShippingMethodDto is a class member of type ShippingMethodDto. Either in the aforementioned methods or in other event handler methods, data entered by the customer needs to be retrieved/saved to this DTO.

  6. Implement the ValidationGroup property. This property is used internally by the framework.
    Example: implementing ValidationGroup
public string ValidationGroup { get; set; }
    1. Build your shipping provider project containing the configuration control. You may separate the shipping provider and the configuration control. There is no need for them to be in the same project except for convenience.
    2. Add a reference to your shipping provider method in the Commerce Manager project, if this has not been done.
    3. Copy the ConfigurateShippingMethod.ascx into a new folder under the Shared folder location Apps/Order/Shipping/Plugins/Shipping Method Name. The shipping method name does not have to be the name of the shipping provider; it can be more informational, representing a shipping provider or shipping type, for example, FedEx24Hour.
    4. Build the site.
    5. Go to Commerce Manager > Administration > Order System > Shipping > Shipping Methods > Language.
    6. Click New.
    7. Configure the new shipping method. Select your new shipping provider from the list of shipping providers. Use the same system name as you named the folder in step 9 and set it to active.
    8. Save the shipping method, re-open, and navigate to the parameters tab. You should see the new shipping provider.
    9. Enter parameter information and save the shipping method.

Accessing shipping provider information

The ShippingManager class lets you retrieve the appropriate case rows, depending on your scenario. This code is used in your GetRate method, or in a method called by GetRate().

For information about using this DataTable, see the WeightJurisdictionGateway.cs GetRate() implementation.

Packages

You can create packages and associate them with shipping providers. In this way, you can define generic package sizes, associate them with a product, then map this generic package to a provider-specific package. For example, the generic LARGE package can map to a 25 Kg Large FedExbox and a USPS Large Flat Rate box.

You can associate them with shipping providers by opening a shipping provider in Commerce Manager, clicking on the Packages tab, and selecting Add Item. You can also associate packages with SKUs in Commerce Manager by changing the Package property on a SKU's Pricing/Inventory tab.

To retrieve package information for a shipping provider, use ShippingMethodDto. This contains two typed data tables with the package information:

  • ShippingPackage. Contains relationship information between shipping providers and packages.
  • Package. Contains all package information.

Last updated: Oct 24, 2016