Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Shipping Calculation Options

Shipping Calculation Options

Overview

Elastic Path provides two shipping options to the user, priced shipping options and unpriced shipping options. The implementations of ShippingOptionService and PricingSnapshotService call the ShippingCalculationService classes. Both services return a ShippingOptionResult object, which contains a list of ShippingOption objects. Each ShippingOption object represents a shipping provider, such as FedEx, which is available for the order. The following diagram illustrates the workflow for unpriced shipping options and priced shipping options:

Unpriced Shipping Options

Unpriced shipping options provide the details of the available shipping options. Unpriced shipping options are returned when a user does not provide an address to ship the order, or if the shipping prices cannot be calculated before placing an order. For example, an unregistered user or incomplete purchase workflow.

Work Flow
  1. Cortex calls the ShippingOptionService class. The ShippingOptionService class is the high-level API that takes Commerce Engine domain objects, such as ShoppingCart and Address.
  2. The ShippingOptionService class calls one of the following:
    • CachingShippingCalculationService: If ShippingOptionService call is already made for the same shopping cart with the same details, CachingShippingCalculationService returns the cached shipping cost, ShippingOptionResult.
    • ShippingCalculationService: For a new cart, the request is passed to this service to get the shipping cost. The ShippingCalculationService uses Data Transfer Objects (DTO) to decouple the underlying calculation from the Commerce Engine.
  3. ShippingCalculationService calls UnpricedShippingCalculationPluginSelector.
  4. UnpricedShippingCalculationPluginSelector selects the default Elastic Path shipping calculation plug-in or a third-party shipping calculation plug-in as required and returns ShippingOptionResult.

    This request returns the available shipping options even if the shipping address and cart details are not provided.

  5. The shipping calculation plug-in returns the shipping cost to Cortex.

Priced Shipping Options

Priced shipping options are provided to a user before completing payment for an order to calculate total price of the order. Priced shipping options are available only if the customer provides the shipping address when completing the order. The PricingSnapshotService examines the shopping cart and returns the pricing details of the shopping cart.
ShoppingCartPricingSnapshot getPricingSnapshotForCart(ShoppingCart shoppingCart);
Work Flow
  1. Cortex calls the ShippingCalculationService, which calls the PricingSnapshotService.

    This service returns the ShoppingCartPricingSnapshot with the cart details.

  2. PricingSnapshotService calls one of the following:
    • ShippingCalculationService: For a new cart, the request is passed to this service to get the shipping cost.
      final ShoppingCartPricingSnapshot shoppingCartPricingSnapshot = pricingSnapshotService.getPricingSnapshotForCart(shoppingCart);
      		final PricedShippableItemContainer<PricedShippableItem> pricedShippableItemContainer =
      				pricedShippableItemContainerTransformer.apply(shoppingCart, shoppingCartPricingSnapshot);
      
      		ShippingCalculationResult pricedShippingOptions = cachingShippingCalculationService.getPricedShippingOptions(pricedShippableItemContainer);
    • CachingShippingCalculationService: If ShippingOption service call is already made for the same shopping cart with the same details, CachingShippingCalculationService returns the cached shipping cost.
  3. ShippingCalculationService calls ShippingCalculationPluginSelector.
  4. ShippingCalculationPluginSelector selects the default Elastic Path shipping calculation plug-in or a third-party shipping calculation plug-in as required.
  5. The shipping cost is returned to Cortex.