Create a custom shipping carrier provider class

To create a custom shipping carrier provider class, you must perform the following:

  1. Create a class to represent the shipping carrier provider.
    In the folder for your custom shipping carrier, add a new class item.
  2. Make the class public.
    Define the class to use the public access specifier.
  3. Implement the IShippingCarrierProvider interface.
    The Telerik.Sitefinity.Modules.Ecommerce.Shipping.Carriers.IShippingCarrierProvider interface requires the following member:
    • ShippingResponseContext GetServiceRates(IShippingRequest shippingData);
      Returns a collection of the shipping rates for the carrier. In this method you have to gather the available rates for the carrier (e.g. call an external service), and wrap them in GenericShippingReponse objects.

Implement the GetServiceRates method

The GetServiceRates method accepts one argument. It is of type Telerik.Sitefinity.Ecommerce.Shipping.Model.IShippingRequest.  It has the following members:

  • DefaultBoxHeight
    Represents the default height of the box used for shipping.
  • DefaultBoxLength
    Represents the default length of the box used for shipping.
  • DefaultBoxWidth
    Represents the default width of the box used for shipping.
  • CartOrder
    Represents the current cart order. The cart order contains the list of products that are going to be purchased. Using it, you can calculate the quantity of each product and its weight.
  • IsMetric
    Specifies whether the measurements are in the metric system.
  • ShipFromAddress1
    Represents the address that the products will be shipped from.
  • ShipFromAddress2
    Represents the second address that the products will be shipped from.
  • ShipFromCity
    Represents the city that the products will be shipped from.
  • ShipFromCountry
    Represents the country that the products will be shipped from.
  • ShipFromState
    Represents the state that the products will be shipped from.
  • ShipFromZip
    Represents the ZIP code that the products will be shipped from.
  • ShipToAddress1
    Represents the address that the products will be shipped to.
  • ShipToAddress2
    Represents the second address that the products will be shipped to.
  • ShipToCity
    Represents the city that the products will be shipped to.
  • ShipToCountry
    Represents the country that the products will be shipped to.
  • ShipToState
    Represents the state that the products will be shipped to.
  • ShipToZip
    Represents the ZIP code that the products will be shipped to.
  • TotalWeight
    Represents the total weight of the products.

In this method you have to get a collection of the available shipping service for your provider. To do this you must perform the following:

  1. Get the shipping manager.
    Get an instance of the ShippingManager object.
  2. Get the carrier provider settings.
    To get the settings for the provider, call the GetShippingCarrierSetting and pass the name of the provider as an argument. The ShippingCarrierProviderSettings instance will contain the settings that you have entered in the administration backend for the provider. You can use one or more of these values to communicate with an external shipping provider. At this time these are the only fields available for holding shipping provider data.  If you require additional data for particular provider, you could hardcode that data in this class or you might consider concatenating that data with other data in one of the existing carrier settings properties and parsing the data values as needed. For more information about configuring the provider in Sitefinity CMS, read the For developers: Install the custom shipping carrier provider.
  3. Calculate the shipping.
    Calculate the shipping parameters like size of the package and weight. You can calculate the parameters of the shipping either manually or by calling an external service.
  4. Get the shipping services.
    Call an external service provided by the shipping carrier to get the available carrier services and their rates. Wrap each of the services in a GenericShippingResponse object and add them to a ShippingResponseContext collection. It is recommended that you specify the carrier services that you want to use with your provider in the Sitefinity CMS backend. Then, you can filter the returned carrier services by the predefined ones. This will secure that you display to the customer only the services that you want. For more information about setting up carrier services in the backend and using them to filter the response from the service carrier, see For developers: Predefine carrier services.
  5. Return the collection of carrier service.
    The method should return the obtained carrier services. Return the ShippingResponseContext collection.

Use the following code sample:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?