Salesforce B2C Commerce can calculate discounts for which a basket almost qualifies. These discounts are called approaching discounts or upsell discounts. The API retrieves the collection of discounts that almost qualify and shows a message for one or more of them in the storefront.
These promotion types have an Alert flag in Business Manager that controls whether customers are notified of the promotion before they fully meet the merchandise conditions:
If the Alert flag is set, you can specify a monetary value threshold that determines how close the customer must be in order to be notified of the discount. If the value is omitted, the customer is alerted as long as their basket is under the discount threshold. For tiered promotions, the alert only triggers for the lowest tier.
Suppose a merchant has three active promotions:
Promotion | Description | Enable upsells | Upsell threshold |
---|---|---|---|
1 | 10% off orders over $150 | true | 50 |
2 | 20% off orders over $200 | true | 75 |
3 | Free ground shipping for orders over $200 | true | 60 |
Case 1
A customer has $140 worth of merchandise in their cart, but doesn't qualify for any of the promotions. The API returns all three approaching discounts because the cart is within the thresholds defined by all three promotions.
Case 2
A customer has $150 worth of merchandise in their cart and receives 10% off their order due to Promotion 1. The merchandise total is now $135. The basket is within the threshold for Promotion 2 (here the $150 is used to determine the threshold, not the $135), and so the customer sees the upsell message for Promotion 2:
"Buy $50 more worth of merchandise and receive
'20% off orders over $200.00'"
The upsell message says "$50 more worth of merchandise" instead of "$65 more." This is because the merchandise total that is used is after product promotions but before order promotions are considered. Merchants typically don't stack order promotions, so when the customer reaches the threshold for the second promotion, the first no longer applies.
The customer doesn't see upsell message for Promotion 3 because the merchandise total after order discounts is $135, which is less than $140 and therefore not within the threshold range defined by that promotion.
Additional support is needed for this feature to your storefront application. To help you, we’ve provided this feature in the SiteGenesis application as follows:
Use these APIs to implement approaching discount in your application.
ApproachingDiscount
The API class ApproachingDiscount, which represents a discount that a customer almost qualifies for based on the merchandise in their cart has these methods:
Method | Description |
---|---|
Discount getDiscount() | The discount the customer receives if they add more merchandise to the cart. |
Money getConditionThreshold() | The amount of merchandise required in the cart in order to receive the discount. |
Money getMerchandiseValue() | The amount of merchandise in the cart contributing towards the condition threshold (is always less than the condition threshold). |
Money getDistanceFromConditionThreshold() | The amount of additional money needed in the order or shipment to receive the discount. |
DiscountPlan
The API class DiscountPlan, which retrieves the collection of discounts the cart almost qualifies for has these methods:
Method | Description |
---|---|
Collection getApproachingOrderDiscounts() | Gets the collection of order discounts that the LineItemCtnr almost qualifies for based on the merchandise total in the cart. Here almost is controlled by thresholds configured at the promotion level. |
Collection getApproachingShippingDiscounts(Shipment shipment, Collection shippingMethods) |
Gets the collection of shipping discounts that the passed shipment almost qualifies for based on the merchandise total in the shipment. Here almost is controlled by thresholds configured at the promotion level. This method only returns discounts for shipping promotions that apply to one of the passed shipping methods. |
Collection getApproachingShippingDiscounts(Shipment shipment, ShippingMethod shippingMethod) | Same as before, but filters by only a single shipping method. |
B2C Commerce calculates approaching promotions based on DiscountPlan and not the cart directly. DiscountPlan is a formal description of discounts to be applied on a line item. B2C Commerce calculates the discounts themselves based on a specific set of promotions, that is, the PromotionPlan. It only selects approaching discounts from promotions in the original PromotionPlan. Removing discounts from the DiscountPlan has no effect on the approaching discounts returned by the API, and isn't supported.
How the APIs Work
Order promotions - The API retrieves the approaching order discounts of an order. An order can have approaching discounts even if it has actual applied discounts. To determine the approaching discounts, B2C Commerce:
Shipping promotions - Approaching shipping discounts are calculated in a similar way. The API retrieves the approaching shipping discounts for each shipment in an order based on a set of shipping methods. A shipment can have approaching shipping discounts even if it has actual applied shipping discounts. When determining the approaching discounts, B2C Commerce:
Example
Using the API, you can retrieve the list of approaching promotions from within a template and show the appropriate messages, as shown in this example:
<!--- Approaching order promotions --->
<isset name="DiscountPlan" value="${dw.campaign.PromotionMgr.getDiscounts(pdict.Basket)}" />
<isloop items="${DiscountPlan.getApproachingOrderDiscounts()}" var="orderDiscount">
Buy <isprint value="${orderDiscount.getDistanceFromConditionThreshold()}" />
more worth of merchandise and receive:
${orderDiscount.getDiscount().getPromotion().getCalloutMsg()}<br/>
</isloop>
<!--- Approaching shipping promotions (for default shipment) --->
<isset name="Shipment" value="${pdict.Basket.getDefaultShipment()}" />
<isset name="ShippingMethods" value=
"${dw.order.ShippingMgr.getShipmentShippingModel(Shipment)
.getApplicableShippingMethods()}" />
<isloop items="${DiscountPlan.getApproachingShippingDiscounts(Shipment, ShippingMethods)}" var="shippingDiscount">
Buy <isprint value="${shippingDiscount.getDistanceFromConditionThreshold()}" />
more worth of merchandise and receive:
${shippingDiscount.getDiscount().getPromotion().getCalloutMsg()}<br/>
</isloop>