dw.order.ShippingMgr
This method is intended for use in custom {@code dw.order.calculate} hook implementations (e.g., in SFRA or SiteGenesis) that override the default basket calculation. Calling this method instead of directly invoking {@code dw.order.calculateShipping} ensures that Commerce App shipping providers registered via {@code sfcc.app.shipping.calculate} are invoked when available, with automatic fallback to the legacy {@code dw.order.calculateShipping} hook or the platform default shipping calculation.
WARNING: Do NOT call this method from within a {@code dw.order.calculateShipping} hook implementation, as this will cause infinite recursion. This method is designed to be called from {@code dw.order.calculate} hooks only.
The dispatch precedence is:
- {@code sfcc.app.shipping.calculate} — if a Commerce App shipping provider is installed.
- {@code dw.order.calculateShipping} — if registered by the storefront.
- Platform default shipping calculation — using product and shipment shipping cost tables.
Typical usage in a custom {@code dw.order.calculate} hook:
var ShippingMgr = require('dw/order/ShippingMgr');
exports.calculate = function (basket) {
// ... product prices, promotions ...
ShippingMgr.applyShipping(basket);
// ... tax ...
basket.updateTotals();
};
For each shipment in the specified line item container, shipment-level shipping cost is calculated. This cost is determined based on the merchandise total of the shipment after all product and order discounts. Only products without or with surcharge product-specific shipping cost count towards this merchandise total. Products with fixed product-specific shipping cost don't count towards the merchandise total used to calculate shipment-level shipping cost. The calculated shipping cost is set at the standard shipping line item of the shipment.
If 'net' taxation is configured for the site, the merchandise total before tax is used. If 'gross' taxation is configured for the site, the merchandise total after tax is used. If no shipping method is set for a shipment, neither product nor shipment-level shipping cost can be calculated. In this case, the amount of the standard shipment shipping line item will be set to N/A, and shipping line items of product line items in this shipment will be removed from the line item container. Special cases for product-level shipping cost:
- if a product is member of multiple shipping cost groups, the lowest shipping cost takes precedence
- if fixed and surcharge shipping cost is defined for a product, the fixed cost takes precedence
- shipping cost defined for a master product is also defined for all variants of this master
- shipping cost is not applied to bundled product line items or options line items