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 Home.
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.
Database Table: tshippingservicelevel
How it works
- To determine a customer's available shipping options, the DeliveryOptionsFormController submits their ShoppingCart to CheckoutService.retrieveShippingOption(shoppingCart).
- The CheckoutService then calls ShippingServiceLevelService.retrieveShippingServiceLevel(shoppingCart) to get a list of of valid shipping service levels for the shipping address
- 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.
- 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.
- At this point, it's time to apply the promotion rules. The shopping cart calls EpRuleEngine.fireOrderPromotionrules(shoppingCart).
- 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.