Class DefaultCartService

    • Field Detail

      • SESSION_CART_PARAMETER_NAME

        public static final java.lang.String SESSION_CART_PARAMETER_NAME
        See Also:
        Constant Field Values
    • Constructor Detail

      • DefaultCartService

        public DefaultCartService()
    • Method Detail

      • addToCart

        @Deprecated
        public void addToCart​(CartModel cartModel,
                              ProductModel productModel,
                              long quantity,
                              UnitModel unitModel)
                       throws InvalidCartException
        Deprecated.
        since 6.2.0
        Description copied from interface: CartService
        Adds to the (existing) CartModel the (existing) ProductModel in the given UnitModel and with the given quantity. If in the cart already an entry with the given product and given unit exists the given quantity is added to the the quantity of this cart entry. After this the cart is calculated.
        Specified by:
        addToCart in interface CartService
        Parameters:
        cartModel - the cart, must exist
        productModel - the product which is added to the cart
        quantity - the quantity of the product
        unitModel - if null ProductService.getOrderableUnit(ProductModel) is used to determine the unit
        Throws:
        InvalidCartException - if the product is a base product OR the quantity is less 1 or no usable unit was found (only when given unit is also null)
      • hasCart

        @Deprecated
        public boolean hasCart()
        Deprecated.
        since 6.2.0
        Specified by:
        hasCart in interface CartService
      • setSessionCart

        public void setSessionCart​(CartModel cart)
        Description copied from interface: CartService
        Attach the cart to a session. Please not that a previously existing session cart is being detached and remove during that operation. It will no longer be available afterwards.
        Specified by:
        setSessionCart in interface CartService
      • getSessionCart

        public CartModel getSessionCart()
        Description copied from interface: CartService
        Returns the cart attached to the current session. The session cart is, just like current user, current currency or language, a part of session data that lives in the session scope.

        If there is no cart attached to the current session yet, this method will automatically create a new cart and attaches it to the current session.

        The creation process is performed by the injected CartFactory. As default a DefaultCartFactory is being used.

        Specified by:
        getSessionCart in interface CartService
      • internalGetSessionCart

        protected CartModel internalGetSessionCart()
      • calculateCart

        @Deprecated
        public boolean calculateCart​(CartModel cartModel)
        Deprecated.
        since 6.2.0
        Description copied from interface: CartService
        Calculates the given cartModel and returns true if each entry and after this the CartModel was calculated. Thereby any invalid entry will be automatically removed.
        Specified by:
        calculateCart in interface CartService
        Parameters:
        cartModel - the CartModel
        Returns:
        false if the cartModel was already calculated.
      • updateQuantities

        @Deprecated
        public void updateQuantities​(CartModel cart,
                                     java.util.List<java.lang.Long> quantities)
        Deprecated.
        since 6.2.0
        Description copied from interface: CartService
        Updates the quantities of each cart entry with the list of quantities. If the quantity value is 0 the cart entry is removed.
        Specified by:
        updateQuantities in interface CartService
        Parameters:
        cart - the cart where the quantities are updated
        quantities - the new quantity list for each cart entry
      • updateQuantities

        public void updateQuantities​(CartModel cart,
                                     java.util.Map<java.lang.Integer,​java.lang.Long> quantities)
        Description copied from interface: CartService
        Updates multiple cart entry quantities at once. Entries that receive a quantity < 1 will be removed as well as entries that receive NULL as quantity value. Refreshes a given cart instance after that.

        Entries with entry numbers that do not occur in the parameter map are not touched.

        Specified by:
        updateQuantities in interface CartService
        Parameters:
        cart - the cart to update cart entry quantities at
        quantities - the entry specific quantities as map of { entry number -> quantity }
      • appendToCart

        public void appendToCart​(CartModel sourceCart,
                                 CartModel targetCart)
        Description copied from interface: CartService
        Clones all entries of source cart to the target cart. After this call, the target cart needs recalculation. To do it, use CalculationService. The target cart is also not persisted after this method call.
        Specified by:
        appendToCart in interface CartService
        Parameters:
        sourceCart - the cart providing the entries to copy
        targetCart - the target cart to create new entries for
      • changeCurrentCartUser

        public void changeCurrentCartUser​(UserModel user)
        Description copied from interface: CartService
        Changes the user of the session cart to the given user. Please mind that the session cart may need recalculation after this call, as the price discounts may be user dependent. In case there is no session cart at the time of this method call, one will be created.
        Specified by:
        changeCurrentCartUser in interface CartService
        Parameters:
        user - new session cart user
      • postProcessClonedEntries

        protected void postProcessClonedEntries​(java.util.Collection<CartEntryModel> sourceClones,
                                                int lastEntryNo,
                                                CartModel targetCart)
        Rearrange cloned entries numbers according to last entry number from the target.
      • setAddToCartStrategy

        public void setAddToCartStrategy​(AddToCartStrategy addToCartStrategy)
      • setOrderCalculation

        public void setOrderCalculation​(OrderCalculation orderCalculation)
      • setCartFactory

        public void setCartFactory​(CartFactory cartFactory)
      • changeSessionCartCurrency

        public void changeSessionCartCurrency​(CurrencyModel currency)
        Description copied from interface: CartService
        Changes the currency of the session cart to the given currency. Please mind that the session cart need recalculation after this call. In case there is no session cart at the time of this method call, one will be created.
        Specified by:
        changeSessionCartCurrency in interface CartService
        Parameters:
        currency - new session cart currency
      • createCartFromQuote

        public CartModel createCartFromQuote​(QuoteModel quote)
        Description copied from interface: CartService
        Creates a new cart based on the given QuoteModel. Please note that it is the caller's responsibility to persist the new cart returned by this method. The quote passed into this method will not be affected by its logic.
        Specified by:
        createCartFromQuote in interface CartService
        Parameters:
        quote - the quote model
        Returns:
        the new cart model
      • setCreateCartFromQuoteStrategy

        public void setCreateCartFromQuoteStrategy​(CreateCartFromQuoteStrategy createCartFromQuoteStrategy)