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.
- Cortex calls the ShippingOptionService class. The ShippingOptionService class is the high-level API that takes Commerce Engine domain objects, such as ShoppingCart and Address.
- 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.
- ShippingCalculationService calls UnpricedShippingCalculationPluginSelector.
- 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.
- The shipping calculation plug-in returns the shipping cost to Cortex.
Priced Shipping Options
ShoppingCartPricingSnapshot getPricingSnapshotForCart(ShoppingCart shoppingCart);
- Cortex calls the ShippingCalculationService, which calls
the PricingSnapshotService.
This service returns the ShoppingCartPricingSnapshot with the cart details.
-
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.
- ShippingCalculationService: For a new cart, the
request is passed to this service to get the shipping
cost.
- ShippingCalculationService calls ShippingCalculationPluginSelector.
- ShippingCalculationPluginSelector selects the default Elastic Path shipping calculation plug-in or a third-party shipping calculation plug-in as required.
- The shipping cost is returned to Cortex.