public class DefaultSaleStrategy<P extends Product,U extends User> extends AbstractChargeStrategy<P,U> implements SaleStrategy<P,U>
Modifier and Type | Field and Description |
---|---|
protected LockStrategy<P,U> |
lockStrategy |
taxStrategy
productService, scanHierarchy
Constructor and Description |
---|
DefaultSaleStrategy() |
Modifier and Type | Method and Description |
---|---|
void |
actionOnPurchase(List<P> product,
U user,
String sessionId)
On an event where a User made a purchase
|
void |
actionOnRating(P product,
U user,
String sessionId)
On user Rating; if there is rating ability then any custom action
|
void |
actionOnVisit(P product,
U user,
String sessionId)
On an event where a User visited the products
|
protected <CONTEXT> void |
applyDiscount(Amount amt,
P product,
Number quantity,
U user,
List<PromotionForUser> promotions,
CONTEXT context)
Apply discount on product.
|
protected <CONTEXT> void |
applyTax(Amount amt,
P product,
Number quantity,
U user,
String currency,
List<PromotionForUser> promotions,
CONTEXT context) |
<CONTEXT> List<Boolean> |
areProductsAvailableToBeSold(List<P> products,
U user,
String sessionId,
CONTEXT context)
Are these products for Sale
|
<CONTEXT> Amount |
calculate(P product,
Number quantity,
U user,
String currency,
List<PromotionForUser> promotions,
CONTEXT context)
Calculate
Amount for product in the given context. |
protected Amount |
getDefaultAmtForMissingData(Price price)
If any amount is null due to data missing; then what should be returned.
|
LockStrategy<P,U> |
getLockStrategy()
An optional
LockStrategy |
<CONTEXT> Price |
getPrice(P product,
U user,
CONTEXT context)
Override to customize which price is used, in case of multi-currency variable pricing etc.
|
Number |
getUnitsInStock(P product,
U user,
String sessionId)
Get the number of units in Stock available for
purchase.
|
<CONTEXT> Boolean |
isProductAvailableToBeSold(P product,
U user,
String sessionId,
CONTEXT context)
The product is not for sale, if
Product.getCurrentInventory() <= 0 or the
Product.getRegularPrice() is 0 or null. |
void |
setLockStrategy(LockStrategy<P,U> lockStrategy)
An optional
LockStrategy |
protected Double |
validateFinalPrice(P product,
Double finalPrice)
Validation to perform checks to make it fool-proof like avoid making stupid mistakes like Zero products etc.
|
applyTax, calculate, getTaxStrategy, getVersion, setTaxStrategy
getProductService, getRepresentativeProduct, isScanHierarchy, setProductService, setScanHierarchy
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
calculate
getVersion
protected LockStrategy<P extends Product,U extends User> lockStrategy
protected <CONTEXT> void applyDiscount(Amount amt, P product, Number quantity, U user, List<PromotionForUser> promotions, CONTEXT context)
protected <CONTEXT> void applyTax(Amount amt, P product, Number quantity, U user, String currency, List<PromotionForUser> promotions, CONTEXT context)
protected Double validateFinalPrice(P product, Double finalPrice) throws javax.validation.ValidationException
finalPrice
- javax.validation.ValidationException
public <CONTEXT> Price getPrice(P product, U user, CONTEXT context)
protected Amount getDefaultAmtForMissingData(Price price)
price
- as PriceAmount
public <CONTEXT> Amount calculate(P product, Number quantity, U user, String currency, List<PromotionForUser> promotions, CONTEXT context)
Amount
for product in the given context.
Amount.getBase()
is considered the total with regular price without discountscalculate
in interface ChargeStrategy<P extends Product,U extends User>
product
- as Pquantity
- as Numberuser
- as U @NUllable truecurrency
- as String @nullable true. A null implies default currency#getPrices(Product, User, Object...)
public <CONTEXT> Boolean isProductAvailableToBeSold(P product, U user, String sessionId, CONTEXT context)
Product.getCurrentInventory()
<= 0 or the
Product.getRegularPrice()
is 0 or null.
isProductAvailableToBeSold
in interface SaleStrategy<P extends Product,U extends User>
product
- as Puser
- as U @nullable truepublic <CONTEXT> List<Boolean> areProductsAvailableToBeSold(List<P> products, U user, String sessionId, CONTEXT context)
SaleStrategy
areProductsAvailableToBeSold
in interface SaleStrategy<P extends Product,U extends User>
products
- as List of Puser
- as U @nullable truepublic Number getUnitsInStock(P product, U user, String sessionId)
SaleStrategy
getUnitsInStock
in interface SaleStrategy<P extends Product,U extends User>
product
- as Puser
- as U @nullable truesessionId
- as String @nullable truepublic void actionOnPurchase(List<P> product, U user, String sessionId)
SaleStrategy
actionOnPurchase
in interface SaleStrategy<P extends Product,U extends User>
public void actionOnVisit(P product, U user, String sessionId)
SaleStrategy
actionOnVisit
in interface SaleStrategy<P extends Product,U extends User>
product
- as Puser
- as Upublic void actionOnRating(P product, U user, String sessionId)
SaleStrategy
actionOnRating
in interface SaleStrategy<P extends Product,U extends User>
product
- as Puser
- as Upublic LockStrategy<P,U> getLockStrategy()
LockStrategy
getLockStrategy
in interface SaleStrategy<P extends Product,U extends User>
public void setLockStrategy(LockStrategy<P,U> lockStrategy)
LockStrategy
LockStrategy
- @nullable trueCopyright © 2018. All rights reserved.