Skip navigation links
com.neurosys.ecom.cart.service

Class AbstractCartService<P extends Product,S,R,U extends User>

    • Field Detail

      • saleStrategy

        protected SaleStrategy<P extends Product,U extends User> 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
      • persistSessionCarts

        protected boolean persistSessionCarts
        If true, will persist session carts until they are cleared (On Action where cart is null or blank). Useful to track Abandoned carts
        Default value:
        false
    • Constructor Detail

      • AbstractCartService

        public AbstractCartService()
      • AbstractCartService

        public AbstractCartService(ProductService<P> productService)
    • Method Detail

      • getSessionId

        protected abstract String getSessionId(S session)
        Get the Id associated with the Session
        Parameters:
        session - as SESSION
        Returns:
      • getUserId

        protected abstract String getUserId(S session)
        Get the User Id associated with the Session
        Parameters:
        session - as SESSION
        Returns:
      • getUser

        protected abstract U getUser(S session)
        Get the User associated with the Session
        Parameters:
        session - as SESSION
        Returns:
      • getOrigin

        protected abstract String getOrigin(S session,
                                            R request)
        Get the origin of the user Request
        Parameters:
        session - as SESSION
        Returns:
      • setCartToSession

        protected abstract void setCartToSession(S session,
                                                 Cart c)
        The Session is expected to be related to the Cart it carries. Ability to Get that.
        Parameters:
        session - as SESSION
      • getCartFromSession

        protected abstract Cart getCartFromSession(S session)
        The Session is expected to be related to the Cart it carries. Ability to Set that.
        Parameters:
        session - as SESSION
        Returns:
      • getCartForSession

        public Cart getCartForSession(S _session,
                                      String type)
        Description copied from interface: CartService
        Some carts like Shopping may exist in Session or persisted.
        So allow a dynamic priority based mechanism or retrieving the Cart
        Specified by:
        getCartForSession in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        _session - as type extends Object (meant to be a Context or Session Object)
        Returns:
      • convertToProductQuantityMap

        public Map<P,Number> convertToProductQuantityMap(Cart cart)
        Description copied from interface: CartService
        Convert a given Cart to a Product Quantity Map.
        The cart only contains references to the actual Product entities. This method one to derive the full map from the Cart reference data.

        One may not always assume quantity to be an Integer, hence Number is used. While default implementations will assume INteger values (like WicketCartService), one may write their own implementation to use a more appropriate format if necessary.
        Specified by:
        convertToProductQuantityMap in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        cart - as Cart
        Returns:
        Map of Product to Item Quantity
        See Also:
        to 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}
      • convertToProductList

        public List<P> convertToProductList(Cart cart)
        Description copied from interface: CartService
        Convert a given Cart to a Product List. (with repeats if multiple quantities of the product exist in the Cart)
        The cart only contains references to the actual Product entities. This method one to derive the full map from the Cart reference data.
        Specified by:
        convertToProductList in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        cart - as Cart
        Returns:
        List of products
      • validateCart

        public void validateCart(Cart cart,
                                 S session)
                          throws Exception
        Validate requested Stock positions in the Cart etc.
        Note: If there is no saleStrategy and Product.getCurrentInventory() is NULL (not 0 but strictly NULL), then it will skip the inventory check for that product.
        Specified by:
        validateCart in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        cart - as Cart
        session - as SESSION @nullable true
        Throws:
        Exception - - In case of some validation exception etc while accepting the Cart
      • mergeCarts

        public Cart mergeCarts(S session,
                               String cartType,
                               Cart existingCart,
                               Cart newSubCart)
        Some operations require sub-carts to be added/merged with an existing Cart. (INTERSECTION)
        This defines the merge operation. This implementation will update the products provided in the newSubCart that already existing and add the ones that don't.
        It will leave existing products unaffected that are there in the existingCart and not mentioned in newSubCart.
        This operation will also try to maintain the order in the existingCart for the existing items. The modified and new will come @ the end of the List

        In addition to the basic products a 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.
        Specified by:
        mergeCarts in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        session - as SESSION - unused; passed onto Event Handler
        cartType - as String - unused; passed onto Event Handler
        existingCart - as Cart @nullable false; but cart can be empty
        newSubCart - as Cart @nullable true
        Returns:
        Cart ; this implementation this is the same as existingCart Object
      • subtractCart

        public Cart subtractCart(S session,
                                 String cartType,
                                 Cart existingCart,
                                 Cart cartToBeSubtracted)
        This operation will remove a cart from the existingCart
        In this implementation; a single mention of a the to-be-removed product will remove all product instances from the cart.
        This operation will also try to maintain the order in the existingCart for the existing items.
        Specified by:
        subtractCart in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        session - as SESSION - unused; passed onto Event Handler
        cartType - as String - unused; passed onto Event Handler
        existingCart - as Cart @nullable false; but cart can be empty
        cartToBeSubtracted - as Cart @nullable true
        TODO: Add unit test case
        Returns:
        Cart
      • actionOnUpdateCartType

        public void actionOnUpdateCartType(S session,
                                           R request,
                                           String cartType,
                                           Cart cart)
                                    throws Exception
        The required data is extracted from the form, one can script their action on the type of cart here.
        Specified by:
        actionOnUpdateCartType in interface CartService<P extends Product,S,R,U extends User>
        Parameters:
        cartType - as String
        cart - as Cart
        session - as SESSION impl like EComSession
        Throws:
        Exception - - In case of some validation exception etc while accepting the Cart
      • setProductService

        public void setProductService(ProductService<P> productService)
      • isPersistSessionCarts

        public boolean isPersistSessionCarts()
        If true, will persist session carts until they are cleared (On Action where cart is null or blank). Useful to track Abandoned carts
        Default value:
        false
      • setPersistSessionCarts

        public void setPersistSessionCarts(boolean persistSessionCarts)
        If true, will persist session carts until they are cleared (On Action where cart is null or blank). Useful to track Abandoned carts
        Default value:
        false
      • getSaleStrategy

        public 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
      • setSaleStrategy

        public 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

Copyright © 2018. All rights reserved.