P
- as Product
U
- as AbstractUser
public class DefaultPromotionStrategy<P extends Product,U extends IGenericEcomUser> extends AbstractChargeStrategy<P,U> implements PromotionStrategy<P,U>
PromotionStrategy
for this applicationModifier and Type | Field and Description |
---|---|
static MarshalUtils.GenericTransformer<PromotionForUser,String> |
PROMOTION_STRING_TRANSFORMER
Create a Notation - PromotionName:UserId:CouponCode
|
protected PromotionService<Promotion> |
promotionService |
static MarshalUtils.GenericTransformer<String,PromotionForUser> |
STRING_PROMOTION_TRANSFORMER
Read the Notation - PromotionName:UserId:CouponCode to produce a PromotionForUser transient object
|
taxStrategy
productService, scanHierarchy
Constructor and Description |
---|
DefaultPromotionStrategy() |
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)
Calculate raw amount for product(s)
|
<CONTEXT> Amount |
calculate(P product,
Number quantity,
U user,
String currency,
List<PromotionForUser> promotions,
CONTEXT context)
By default this Strategy does not do anything @ a product level.
|
void |
commitPromotionsForOrder(Order order)
Update Promotions persisted state; to track count, usage of promotion etc.
|
protected Amount |
discountForPromotion(PromotionForUser promotionForUser,
Map<P,Number> productQtyMap,
String currency,
Amount subTotal) |
protected <CONTEXT> String |
getCouponCode(CONTEXT context)
By default uses context[0][1]
|
<CONTEXT> List<PromotionForUser> |
getPromotions(Map<P,Number> productQtyMap,
U user,
Amount subTotal,
Number quantityTotal,
CONTEXT context)
Note: Default implementation looks for any item not on SALE to grant the Discount.
|
protected List<PromotionForUser> |
getPromotions(String userEmail,
String couponCode) |
PromotionService<Promotion> |
getPromotionService() |
protected <CONTEXT> String |
getUserEmailOrId(CONTEXT context)
By default uses context[0][0]
|
protected Double |
includeProductPriceForDiscount(P p,
PromotionForUser promotionForUser,
String currency,
Amount subTotal)
If this returns a double then in cases where the Discount is variable on the Cart amount; this will contribute.
|
void |
setPromotionService(PromotionService<Promotion> promotionService) |
protected <CONTEXT> void |
validate(Map<P,Number> productQtyMap,
String userEmail,
String couponCode,
CONTEXT context)
(Default impl) does nothing.
|
protected void |
validate(PromotionForUser promotionForUser,
String currency,
Amount subTotal,
Number totalQuantity) |
applyTax, getTaxStrategy, getVersion, setTaxStrategy
getProductService, getRepresentativeProduct, isScanHierarchy, setProductService, setScanHierarchy
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getVersion
protected PromotionService<Promotion> promotionService
public static final MarshalUtils.GenericTransformer<PromotionForUser,String> PROMOTION_STRING_TRANSFORMER
public static final MarshalUtils.GenericTransformer<String,PromotionForUser> STRING_PROMOTION_TRANSFORMER
protected List<PromotionForUser> getPromotions(String userEmail, String couponCode)
protected <CONTEXT> String getUserEmailOrId(CONTEXT context)
context
- with first vararg as Object[] in default implementation, can override to anythingprotected <CONTEXT> String getCouponCode(CONTEXT context)
context
- with first vararg as Object[] in default implementation, can override to anythingprotected <CONTEXT> void validate(Map<P,Number> productQtyMap, String userEmail, String couponCode, CONTEXT context) throws javax.validation.ValidationException
javax.validation.ValidationException
- ; Soft fail, by throwing ValidationException
public <CONTEXT> List<PromotionForUser> getPromotions(Map<P,Number> productQtyMap, U user, Amount subTotal, Number quantityTotal, CONTEXT context) throws javax.validation.ValidationException
getPromotions
in interface PromotionStrategy<P extends Product,U extends IGenericEcomUser>
productQtyMap
- 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
protected void validate(PromotionForUser promotionForUser, String currency, Amount subTotal, Number totalQuantity) throws Continue, javax.validation.ValidationException
Continue
javax.validation.ValidationException
protected Double includeProductPriceForDiscount(P p, PromotionForUser promotionForUser, String currency, Amount subTotal)
Amount.getCurrency()
.
p
- as Product
promotionForUser
- as PromotionForUser
currency
- as StringsubTotal
- as Amount
protected Amount discountForPromotion(PromotionForUser promotionForUser, Map<P,Number> productQtyMap, String currency, Amount subTotal)
public final <CONTEXT> Amount calculate(P product, Number quantity, U user, String currency, List<PromotionForUser> promotions, CONTEXT context)
DefaultDiscountStrategy
for that.calculate
in interface ChargeStrategy<P extends Product,U extends IGenericEcomUser>
product
- as Pquantity
- as Numberuser
- as U @NUllable truecurrency
- as String @nullable true. A null implies default currencypublic <CONTEXT> Amount calculate(Map<P,Number> productQtyMap, U user, String currency, List<PromotionForUser> promotions, Amount subTotal, Number totalQuantity, CONTEXT context) throws javax.validation.ValidationException
CumulativeChargeStrategy
calculate
in interface CumulativeChargeStrategy<P extends Product,U extends IGenericEcomUser>
calculate
in interface PromotionStrategy<P extends Product,U extends IGenericEcomUser>
calculate
in class AbstractChargeStrategy<P extends Product,U extends IGenericEcomUser>
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)
@Transactional(readOnly=false) public void commitPromotionsForOrder(Order order)
Order
then commit them to Data Store.
commitPromotionsForOrder
in interface PromotionStrategy<P extends Product,U extends IGenericEcomUser>
public PromotionService<Promotion> getPromotionService()
public void setPromotionService(PromotionService<Promotion> promotionService)
Copyright © 2018. All rights reserved.