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

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Shipping options

Shipping options

During the checkout process, customers have the opportunity to select their Shipping Service level. After the shipping address has been selected, the shipping service levels available are determined by the region to which their products are being shipped; available shipping options for different regions are configured in the Commerce Manager. For more information on how that is done, see the Shipping Regions and Shipping Service Levels sections in the Commerce Manager User Guide.

Key Classes and Files

The relevant files and classes can be roughly subdivided into those that deal mostly with displaying the appropriate ShippingServiceLevels and those that deal with the costs associated with those service levels.

Shipping Service Levels

  • DeliveryOptionsFormControllerImpl - Handles display and selection of delivery options.
  • CheckoutServiceImpl - retrieveShippingOption(shoppingCart) - Sets the valid shipping levels in the ShoppingCart for display.
  • ShippingServiceLevelServiceImpl - Retrieves valid shipping service levels for a region, gets shipping cost calculations, takes into account shipping-related promotions.
  • ShippingServiceLevel - A shipping option associated with a shipping region.
  • ShoppingCartImpl - Gets the shipping cost based on the selected shipping service level.
  • deliveryOptions.vm - The velocity template that displays the currently available shipping service levels and their costs.
  • viewCart.vm - The velocity template that displays the current shopping cart, and can display estimated shipping costs.
  • VM_global_library.vm - Contains the velocity macro definition #displayShippingOptions which is similar to the code in deliveryOptions.vm in that it displays shipping service levels and costs associated with a given address.

Shipping Costs associated with different service levels

  • EpRuleEngine - applies promotion rules that may affect shipping costs.
  • ShippingCostCalculationMethod - calculates shipping costs for a given ShoppingCart, depending on which shipping option was selected, which promotions are in effect, the customer's shipping region, and the shipping cost calculation method selected for use in the Commerce Manager.
  • AbstractShippingCostCalculationMethodImpl - Abstract implementation of a shipping cost calculation.
  • The following classes extend AbstractShippingCostCalculationImpl to implement specific shipping cost calculations.
    • CostPerUnitWeightMethodImpl
    • FixedBaseAndCostPerUnitWeightMethodImpl
    • FixedBaseAndOrderTotalPercentageMethodImpl
    • FixedPriceMethodImpl
    • OrderTotalPercentageMethodImpl

Database Table: tshippingservicelevel

How it works

  1. To determine a customer's available shipping options, the DeliveryOptionsFormController submits their ShoppingCart to CheckoutService.retrieveShippingOption(shoppingCart).
  2. The CheckoutService then calls ShippingServiceLevelService.retrieveShippingServiceLevel(shoppingCart) to get a list of of valid shipping service levels for the shipping address
    1. It does this by asking the database for all the ShippingServiceLevels in the tshippingservicelevel table, then filtering out the levels that do not apply to the region in which the shipping address is located.
    2. The CheckoutService method then calls the ShoppingCart.setShippingServiceLevelList(), which in turn calls calculateShippingCost(shoppingCart) on each ServiceLevel in the list to force it to calculate its shipping cost based on what's in the shopping cart, and sets the first ShippingLevel as the default selected level in the ShoppingCart.
    3. At this point, it's time to apply the promotion rules. The shopping cart calls EpRuleEngine.fireOrderPromotionrules(shoppingCart).
      1. The Rule Engine loops through all the CartItems in the ShoppingCart, using the drools engine to apply promotions rules. See the Promotion rule engine for information on how these work.
  3. The available service levels are then displayed on the screen by the deliveryOptions.vm velocity template. The page is dynamically updated via Javascript and DWR Ajax remoting framework.
  4. The UI Javascript code in deliveryOptions.vm calls ShippingServiceLevel.getShippingCost() for each service level, whereupon the shipping costs are calculated and displayed next to the shipping options.