public abstract class AbstractCartService<P extends Product,S,R,U extends User> extends Object implements CartService<P,S,R,U>
CartService uses SESSION.
It assumes CartItem.getName() as he Key, however if you wish to override,
look @ CartItem.getKey(), #getProductKey(Product), #getProductsForKeys(Collection), StrategiesService.strategiesCalcData(List, IGenericEcomUser, String, String, Collection, com.neurosys.ecom.wicket.components.EComSession, String).
ChangeGenerator; it will also generate Events of TypeCartProductTransformService| Modifier and Type | Field and Description |
|---|---|
protected boolean |
persistSessionCarts
If true, will persist session carts until they are cleared (On Action where cart is null or blank).
|
protected SaleStrategy<P,U> |
saleStrategy
When allowing to add items to cart, if a
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistence |
CART_TYPE_SHOPPING, CART_TYPE_WISHLIST| Constructor and Description |
|---|
AbstractCartService() |
AbstractCartService(ProductService<P> productService) |
| Modifier and Type | Method and Description |
|---|---|
void |
actionOnUpdateCartType(S session,
R request,
String cartType,
Cart cart)
The required data is extracted from the form, one can script their
action on the type of cart here.
|
void |
addChangeListener(ChangeListener changeListener)
Allow Notify all
ChangeListeners about a change |
List<P> |
convertToProductList(Cart cart)
Convert a given Cart to a Product List.
|
Map<P,Number> |
convertToProductQuantityMap(Cart cart)
Convert a given Cart to a Product Quantity Map.
|
Cart |
getCartForSession(S _session,
String type)
Some carts like Shopping may exist in Session or persisted.
|
Cart |
getCartForUser(String userId,
String type)
Some carts like a WishList maybe persistent
so allow to retrieve it.
|
protected abstract Cart |
getCartFromSession(S session)
The Session is expected to be related to the
Cart it carries. |
CartProductTransformService<P,CartItem> |
getCartProductTransform()
Handle All conversions
|
List<ChangeListener<Object>> |
getListeners()
Get list directly.
|
protected abstract String |
getOrigin(S session,
R request)
Get the origin of the user Request
|
ProductService<P> |
getProductService() |
SaleStrategy<P,U> |
getSaleStrategy()
When allowing to add items to cart, if a
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistence |
protected abstract String |
getSessionId(S session)
Get the Id associated with the Session
|
protected abstract U |
getUser(S session)
Get the User associated with the Session
|
UserAttributesDao<UserAttribute> |
getUserAttributeDao() |
protected abstract String |
getUserId(S session)
Get the User Id associated with the Session
|
boolean |
isPersistSessionCarts()
If true, will persist session carts until they are cleared (On Action where cart is null or blank).
|
Cart |
mergeCarts(S session,
String cartType,
Cart existingCart,
Cart newSubCart)
Some operations require sub-carts to be added/merged with an existing
Cart. |
void |
notifyAllListeners(Object object)
Whenever a node is selected/updated, it also notifies its listeners.
|
Cart |
saveCart(String type,
Cart cart,
S session,
R request)
Save the
Cart to persist so it can be retrieved using CartService.getCartForUser(String, String) |
void |
setCartProductTransform(CartProductTransformService<P,CartItem> cartProductTransform)
Handle All conversions
|
protected abstract void |
setCartToSession(S session,
Cart c)
The Session is expected to be related to the
Cart it carries. |
void |
setListeners(List<ChangeListener<Object>> listeners)
Set list directly.
|
void |
setPersistSessionCarts(boolean persistSessionCarts)
If true, will persist session carts until they are cleared (On Action where cart is null or blank).
|
void |
setProductService(ProductService<P> productService) |
void |
setSaleStrategy(SaleStrategy<P,U> saleStrategy)
When allowing to add items to cart, if a
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistence |
void |
setUserAttributeDao(UserAttributesDao<UserAttribute> userAttributeDao) |
Cart |
subtractCart(S session,
String cartType,
Cart existingCart,
Cart cartToBeSubtracted)
This operation will remove a cart from the existingCart
|
void |
validateCart(Cart cart,
S session)
Validate requested Stock positions in the Cart etc.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCartSessionId, getCartUserIdprotected SaleStrategy<P extends Product,U extends User> saleStrategy
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistenceprotected boolean persistSessionCarts
public AbstractCartService()
public AbstractCartService(ProductService<P> productService)
protected abstract String getSessionId(S session)
session - as SESSIONprotected abstract String getUserId(S session)
session - as SESSIONprotected abstract U getUser(S session)
session - as SESSIONprotected abstract String getOrigin(S session, R request)
session - as SESSIONprotected abstract void setCartToSession(S session, Cart c)
Cart it carries. Ability to Get that.session - as SESSIONprotected abstract Cart getCartFromSession(S session)
Cart it carries. Ability to Set that.session - as SESSIONpublic Cart getCartForUser(String userId, String type)
CartServicegetCartForUser in interface CartService<P extends Product,S,R,U extends User>userId - as Stringtype - as StringCartpublic Cart getCartForSession(S _session, String type)
CartServiceCartgetCartForSession in interface CartService<P extends Product,S,R,U extends User>_session - as type extends Object (meant to be a Context or Session Object)public Cart saveCart(String type, Cart cart, S session, R request)
CartServiceCart to persist so it can be retrieved using CartService.getCartForUser(String, String)public Map<P,Number> convertToProductQuantityMap(Cart cart)
CartServiceWicketCartService),
one may write their own implementation to use a more appropriate format if necessary.convertToProductQuantityMap in interface CartService<P extends Product,S,R,U extends User>cart - as CartMap of Product to Item Quantityto get {@link Cart#getItems()} as this Map isnt scalable; like hierarchy info etc. This is ok for a flat list of all items and their quantity in a {@link Cart}public List<P> convertToProductList(Cart cart)
CartServiceconvertToProductList in interface CartService<P extends Product,S,R,U extends User>cart - as CartList of productspublic void validateCart(Cart cart, S session) throws Exception
saleStrategy and Product.getCurrentInventory() is NULL (not 0 but strictly NULL), then it will skip the inventory check for that product.validateCart in interface CartService<P extends Product,S,R,U extends User>cart - as Cartsession - as SESSION @nullable trueException - - In case of some validation exception etc while accepting the Cartpublic Cart mergeCarts(S session, String cartType, Cart existingCart, Cart newSubCart)
Cart. (INTERSECTION) List
Cart may contain additional details like Cart.getCurrency(). In this case the default expected behavior
is defined as the latest/update overwriting the previouscart property.mergeCarts in interface CartService<P extends Product,S,R,U extends User>session - as SESSION - unused; passed onto Event HandlercartType - as String - unused; passed onto Event HandlerexistingCart - as Cart @nullable false; but cart can be emptynewSubCart - as Cart @nullable trueCart ; this implementation this is the same as existingCart Objectpublic Cart subtractCart(S session, String cartType, Cart existingCart, Cart cartToBeSubtracted)
subtractCart in interface CartService<P extends Product,S,R,U extends User>session - as SESSION - unused; passed onto Event HandlercartType - as String - unused; passed onto Event HandlerexistingCart - as Cart @nullable false; but cart can be emptycartToBeSubtracted - as Cart @nullable true
Cartpublic void actionOnUpdateCartType(S session, R request, String cartType, Cart cart) throws Exception
actionOnUpdateCartType in interface CartService<P extends Product,S,R,U extends User>cartType - as Stringcart - as Cartsession - as SESSION impl like EComSessionException - - In case of some validation exception etc while accepting the Cartpublic ProductService<P> getProductService()
public void setProductService(ProductService<P> productService)
public UserAttributesDao<UserAttribute> getUserAttributeDao()
public void setUserAttributeDao(UserAttributesDao<UserAttribute> userAttributeDao)
public boolean isPersistSessionCarts()
public void setPersistSessionCarts(boolean persistSessionCarts)
public SaleStrategy<P,U> getSaleStrategy()
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistencepublic void setSaleStrategy(SaleStrategy<P,U> saleStrategy)
saleStrategy
is provided it will rely on it rather than actual inventory data available from persistencepublic CartProductTransformService<P,CartItem> getCartProductTransform()
CartProductTransformServicepublic void setCartProductTransform(CartProductTransformService<P,CartItem> cartProductTransform)
CartProductTransformServicepublic void addChangeListener(ChangeListener changeListener)
ChangeGeneratorChangeListeners about a changeaddChangeListener in interface ChangeGenerator<Object>public void notifyAllListeners(Object object)
ChangeGeneratornotifyAllListeners in interface ChangeGenerator<Object>public List<ChangeListener<Object>> getListeners()
ChangeGeneratorgetListeners in interface ChangeGenerator<Object>public void setListeners(List<ChangeListener<Object>> listeners)
ChangeGeneratorsetListeners in interface ChangeGenerator<Object>Copyright © 2018. All rights reserved.