public interface PromotionStrategy<P extends Product,U extends User> extends CumulativeChargeStrategy<P,U>
Order
ValidationException
that should be explicitly handled.
DefaultDiscountStrategy
and PromotionStrategy
is that this is applicable @ a product level only;
while PromotionStrategy
is applicable @ the cart level and also supports product level.Modifier and Type | Method and Description |
---|---|
<CONTEXT> Amount |
calculate(Map<P,Number> productQtyMap,
U user,
String currency,
List<PromotionForUser> promotions,
Amount subTotal,
Number totalQuantity,
CONTEXT context)
Note: Discounts are DEDUCTED in main / API calcs, so total can be (+), discount part (-) ...
|
void |
commitPromotionsForOrder(Order order)
Update Promotions persisted state; to track count, usage of promotion etc.
|
<CONTEXT> List<PromotionForUser> |
getPromotions(Map<P,Number> productQtyMap,
U user,
Amount subTotal,
Number quantityTotal,
CONTEXT context)
Get a List of
PromotionForUser for the Order of a user |
calculate
getVersion
<CONTEXT> List<PromotionForUser> getPromotions(Map<P,Number> productQtyMap, U user, Amount subTotal, Number quantityTotal, CONTEXT context) throws javax.validation.ValidationException
PromotionForUser
for the Order of a userproductQtyMap
- as Map
of Product to Number (Quantity)user
- as U @NUllable truesubTotal
- as Amount
; many scenarios use the Sub-Total of products to calculate other params. So provide that as a defined context variable. @nullable truequantityTotal
- as Number
; many scenarios use the quantityTotal of products to calculate other params @nullable truecontext
- as additional case driven params that can be supplied @nullable truePromotionForUser
. @Nulable true; No promotions availablejavax.validation.ValidationException
<CONTEXT> Amount calculate(Map<P,Number> productQtyMap, U user, String currency, List<PromotionForUser> promotions, Amount subTotal, Number totalQuantity, CONTEXT context) throws javax.validation.ValidationException
calculate
in interface CumulativeChargeStrategy<P extends Product,U extends User>
productQtyMap
- as Map
of Product to Number (Quantity)user
- as U @NUllable truecurrency
- as String @nullable true. A null implies default currency. Note: If not null then this will override subTotal Amount.getCurrency()
.subTotal
- as Amount
; many scenarios use the Sub-Total of products to calculate other params. So provide that as a defined context variable. @nullable truetotalQuantity
- as Number
; many scenarios use the quantityTotal of products to calculate other params @nullable truecontext
- as additional case driven params that can be supplied @nullable trueAmount.getTotal()
should be positive; while Amount.getDiscount()
should be negative number.
This is because a Discount is DEDUCTED. So while it makes sense to DEDUCT a positive value from TOTAL; the discount itself should be ADDED
hence = >
Existing Total - (This Discount as Total)
Existing Discount - (-This Discount) = Existing Discount + This Discountjavax.validation.ValidationException
Amount.deduct(Amount)
void commitPromotionsForOrder(Order order)
Order
then commit them to Data Store.
Copyright © 2018. All rights reserved.