public class DefaultOrderStrategy<P extends Product,U extends IGenericEcomUser,O extends Order<I>,I extends OrderItem> extends AbstractChargeStrategy<P,U> implements OrderStrategy<P,U,O,I>
Modifier and Type | Field and Description |
---|---|
protected boolean |
blockOrders
A quick set flag if we wish to block taking orders due to any reason like maintenance etc.
|
protected ContextProviderStrategy |
contextProviderStrategy |
protected CumulativeChargeStrategy<P,U> |
discountStrategy |
protected OrderService<O,I> |
orderService |
protected CumulativeChargeStrategy<P,U> |
packagingStrategy |
protected PromotionStrategy<P,U> |
promotionStrategy |
protected SaleStrategy<P,U> |
saleStrategy |
protected CumulativeChargeStrategy<P,U> |
shippingStrategy |
taxStrategy
productService, scanHierarchy
Constructor and Description |
---|
DefaultOrderStrategy() |
Modifier and Type | Method and Description |
---|---|
<CONTEXT> Amount |
calculate(P product,
Number quantity,
U user,
String currency,
List<PromotionForUser> promotions,
CONTEXT context)
Will add amount from
ChargeStrategy.calculate(Product, Number, User, String, List, Object) for each of the following strategies in order @ The product level.The rules of Amount.add(Amount) will apply while adding:
saleStrategy
discountStrategy
promotionStrategy
|
<CONTEXT> O |
createOrder(Map<P,Number> productQtyMap,
U user,
String currency,
List<PromotionForUser> promotions,
Map<String,Object> itemProperties,
boolean persist,
CONTEXT context) |
<CONTEXT> O |
createOrder(Map<P,Number> productQtyMap,
U user,
String currency,
List<PromotionForUser> promotions,
Map<String,Object> itemProperties,
boolean persist,
org.apache.commons.collections.Transformer transformer,
CONTEXT context)
|
protected I |
createOrderItem(O order,
P p,
Amount totalAmtForProduct,
Number quantity,
Map<String,Object> itemProperties)
Override for custom
OrderItem type |
ContextProviderStrategy |
getContextProviderStrategy() |
CumulativeChargeStrategy<P,U> |
getDiscountStrategy() |
protected O |
getOrderInstance()
Override for custom Order type
|
OrderService<O,I> |
getOrderService()
Access to the underlying
OrderService |
CumulativeChargeStrategy<P,U> |
getPackagingStrategy() |
PromotionStrategy<P,U> |
getPromotionStrategy() |
SaleStrategy<P,U> |
getSaleStrategy() |
CumulativeChargeStrategy<P,U> |
getShippingStrategy() |
protected String |
getStrategiesVerson()
JSON Map String of all Strategies version used for the order.
|
boolean |
isBlockOrders()
A quick set flag if we wish to block taking orders due to any reason like maintenance etc.
|
void |
onOrderComplete(O order,
String sessionId)
When an Order is successfully Completed; then some actions should be taken.
|
protected void |
processOrderItem(I item,
Map<String,Object> itemProperties)
Customize
OrderItem data based on properties |
void |
setBlockOrders(boolean blockOrders)
A quick set flag if we wish to block taking orders due to any reason like maintenance etc.
|
void |
setContextProviderStrategy(ContextProviderStrategy contextProviderStrategy) |
void |
setDiscountStrategy(CumulativeChargeStrategy<P,U> discountStrategy) |
void |
setOrderService(OrderService<O,I> orderService) |
void |
setPackagingStrategy(CumulativeChargeStrategy<P,U> packagingStrategy) |
void |
setPromotionStrategy(PromotionStrategy<P,U> promotionStrategy) |
void |
setSaleStrategy(SaleStrategy<P,U> saleStrategy) |
void |
setShippingStrategy(CumulativeChargeStrategy<P,U> shippingStrategy) |
protected void |
validateOrder(O order)
Any validation criteria to allow the order to pass or not.
|
applyTax, calculate, getTaxStrategy, getVersion, setTaxStrategy
getProductService, getRepresentativeProduct, isScanHierarchy, setProductService, setScanHierarchy
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getVersion
protected CumulativeChargeStrategy<P extends Product,U extends IGenericEcomUser> shippingStrategy
protected CumulativeChargeStrategy<P extends Product,U extends IGenericEcomUser> packagingStrategy
protected CumulativeChargeStrategy<P extends Product,U extends IGenericEcomUser> discountStrategy
protected SaleStrategy<P extends Product,U extends IGenericEcomUser> saleStrategy
protected PromotionStrategy<P extends Product,U extends IGenericEcomUser> promotionStrategy
protected ContextProviderStrategy contextProviderStrategy
protected boolean blockOrders
validateOrder(Order)
to implement more complex scenarios.
public <CONTEXT> Amount calculate(P product, Number quantity, U user, String currency, List<PromotionForUser> promotions, CONTEXT context)
ChargeStrategy.calculate(Product, Number, User, String, List, Object)
for each of the following strategies in order @ The product level.Amount.add(Amount)
will apply while adding:
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 currencyprotected void validateOrder(O order) throws OrderPlacementException
order
- as OOrderPlacementException
protected void processOrderItem(I item, Map<String,Object> itemProperties)
OrderItem
data based on propertiesitem
- as OrderItemitemProperties
- @nullable true, as Map
of additional properties for each product related (OrderItem). Key in map is same as product identifier (Product.getName()
by default convention)protected I createOrderItem(O order, P p, Amount totalAmtForProduct, Number quantity, Map<String,Object> itemProperties)
OrderItem
typeOrderItem
type objectprotected O getOrderInstance()
Order
type object@Transactional(readOnly=false) public <CONTEXT> O createOrder(Map<P,Number> productQtyMap, U user, String currency, List<PromotionForUser> promotions, Map<String,Object> itemProperties, boolean persist, org.apache.commons.collections.Transformer transformer, CONTEXT context) throws OrderPlacementException
Order
Cart
could be convenient, however most order creation data are also contextual and it would additionally require other services to be part ofthe OrderStrategy
which would not make it clean. For these reasons there is no direct method to accept Cart
.
One can use the following code to support the transition, for example:
Map productQuantityMap = cartService.convertToProductQuantityMap(cart);
order = orderStrategy.createOrder(productQuantityMap, user, null Default Currency, null No promotions, false , orderProcessHelper.deriveContext(user, getRequestCycle()));
or one can use OrderProcessHelper#deriveOrder(Map, IGenericEcomUser, String, Class, Order, String, org.apache.wicket.RequestCycle, org.apache.wicket.Response)
createOrder
in interface OrderStrategy<P extends Product,U extends IGenericEcomUser,O extends Order<I>,I extends OrderItem>
productQtyMap
- as Map
of Product to Number (Quantity)user
- as User
@nullable true (In case of GuestUser
, optional)currency
- as String @nullable true. A null implies default currencypromotions
- as List of Promotion
sitemProperties
- as Map
of additional properties for each product (OrderItem)persist
- as boolean; if true will persist the Order instance and return an Order with Order.getId()
that is also persistedtransformer
- as Transformer (Optional), to perform any additional transformation over the in process Order Object before its persisted @nullable truecontext
- as varargsOrderPlacementException
@Transactional(readOnly=false) public <CONTEXT> O createOrder(Map<P,Number> productQtyMap, U user, String currency, List<PromotionForUser> promotions, Map<String,Object> itemProperties, boolean persist, CONTEXT context) throws OrderPlacementException
createOrder
in interface OrderStrategy<P extends Product,U extends IGenericEcomUser,O extends Order<I>,I extends OrderItem>
OrderPlacementException
#createOrder(Map, IGenericEcomUser, String, List, Map, boolean, Transformer, Object...)
@Transactional(readOnly=false, noRollbackFor=java.lang.Exception.class) public void onOrderComplete(O order, String sessionId)
ChangeListener
hooked into OrderService
or TransactionService
alsoPromotionForUser
sonOrderComplete
in interface OrderStrategy<P extends Product,U extends IGenericEcomUser,O extends Order<I>,I extends OrderItem>
order
- as OChangeGenerator, {@link ChangeListener}, {@link PostOrderProcessStrategy} as possible implementation aids.
protected String getStrategiesVerson()
Order.getStrategiesVersion()
public boolean isBlockOrders()
validateOrder(Order)
to implement more complex scenarios.
public void setBlockOrders(boolean blockOrders)
validateOrder(Order)
to implement more complex scenarios.
public OrderService<O,I> getOrderService()
OrderStrategy
OrderService
getOrderService
in interface OrderStrategy<P extends Product,U extends IGenericEcomUser,O extends Order<I>,I extends OrderItem>
public void setOrderService(OrderService<O,I> orderService)
public SaleStrategy<P,U> getSaleStrategy()
public void setSaleStrategy(SaleStrategy<P,U> saleStrategy)
public CumulativeChargeStrategy<P,U> getShippingStrategy()
public void setShippingStrategy(CumulativeChargeStrategy<P,U> shippingStrategy)
public CumulativeChargeStrategy<P,U> getPackagingStrategy()
public void setPackagingStrategy(CumulativeChargeStrategy<P,U> packagingStrategy)
public CumulativeChargeStrategy<P,U> getDiscountStrategy()
public void setDiscountStrategy(CumulativeChargeStrategy<P,U> discountStrategy)
public PromotionStrategy<P,U> getPromotionStrategy()
public void setPromotionStrategy(PromotionStrategy<P,U> promotionStrategy)
public ContextProviderStrategy getContextProviderStrategy()
public void setContextProviderStrategy(ContextProviderStrategy contextProviderStrategy)
Copyright © 2018. All rights reserved.