Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Loading...
Applies to versions: 14 and higher
Other versions:
ARCHIVED This content is retired and no longer maintained. See the version selector for other versions of this topic.

Shipping gateways and providers

Recommended reading 
Note: This documentation is for the preview version of the upcoming release of CMS 12/Commerce 14/Search & Navigation 14. Features included here might not be complete, and might be changed before becoming available in the public release. This documentation is provided for evaluation purposes only.

In Optimizely 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 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 and IShippingPlugin.
  • Mediachase.Commerce.Catalog.Data. Contains CurrencyAdmin.
  • Mediachase.Commerce.Orders.Dto. Contains ShippingMethodDto.

See also Shipping methods.

Shipping gateways

You select a Shipping Gateway from the Shipping Provider view in the Commerce Admin user interface. 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.

NoteIShippingPlugin is highly recommended. IShippingGateway remains to support 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. Follow these steps to 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 implements 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.

    Note: Remember to register the class with the service container as a service of IShippingPlugin.

    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.
  1. 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.
  2. In Commerce Administration tab > Shipping > Shipping Providers.
  3. Click Create.
  4. Enter a name for the gateway and a system keyword. The keyword must be unique.
  5. Select the gateway that implements IShippingPlugin, which  you created in the previous step.
  6. Click Save.
  7. Go to Shipping > Shipping Methods.
  8. Click Create.
  9. 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.
  10. Click Save.

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 packages 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.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Jul 02, 2021

Recommended reading