API: Shipping for Promotions
While promotions are evaluated and applied as one step of the basket calculation, other steps are:
- Determining product prices
- Calculating taxes
- Calculating shipping costs
You can use the Salesforce B2C Commerce APIs to calculate and
access shipment-level and product-level shipping costs. When using the
applyShippingCost
method
(dw.Order.ShippingMgr
Class), for example, the cart
calculation script is simple:
{
...
dw.order.ShippingMgr.applyShippingCost(basket)
...
}
dw.order.ProductShippingLineItem Class
You can use the B2C Commerce APIs to access product shipping costs. Product line items can have one dependent shipping line item. This shipping line item represents either the fixed or the surcharged shipping cost for this product line item. The price of the shipping line item is per product unit, and the shipping line item has a quantity field. The product shipping line item only exists if the product has individual shipping cost.
The following sample script accesses the product shipping costs:
for(productLineItem : ProductLineItem, shipment.productLineItems)
{
shippingLineItem : ProductShippingLineItem = productLineItem.shippingLineItem;
if(shippingLineItem != null)
{
cost : Money = shippingLineItem.price;
}
}
The following methods of this class support product shipping discounts:
- getAdjustedGrossPrice() : Money
- getAdjustedNetPrice() : Money
- getAdjustedPrice() : Money
- getAdjustedTax() : Money
- getPriceAdjustments() : Collection
dw.order.Shipment Class
Use the methods of this class to return the accumulated value of all shipment shipping line items and all product shipping line items in the shipment. If any of these shipping line items is N/A, the total price is N/A.
dw.order.ShippingLineItem Class
With this class, you can create, retrieve, and remove arbitrary shipping price adjustments (that is, price adjustments not controlled by B2C Commerce) and associate those adjustments with a specific shipping line item. This is useful for merchants who use multiple shipping line items to model various types of shipping charges, instead of just the standard shipping line item for all shipping costs.
dw.order.LineItemCtnr Class
The methods of this class return the accumulated value of all shipment shipping line items and all product shipping line items in the container. If any of these shipping line items is N/A, the total price is N/A.
dw.campaign.PromotionPlan
You can fetch applicable shipping promotions during checkout using the methods in this class. You can also show potential shipping promotions to the customer during the checkout process.