Interface CartService

    • Method Detail

      • setSessionCart

        void setSessionCart​(CartModel cart)
        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.
      • getSessionCart

        CartModel getSessionCart()
        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.

      • removeSessionCart

        void removeSessionCart()
        If existing the current session cart is being detached from this session and removed. Afterwards it's no longer available.
        See Also:
        getSessionCart(), setSessionCart(CartModel)
      • hasSessionCart

        boolean hasSessionCart()
        Returns true if the current session already holds a cart, false otherwise. Please use this instead of getSessionCart() if you like to avoid unnecessary auto-creation of the session cart.
        See Also:
        getSessionCart()
      • hasCart

        @Deprecated
        boolean hasCart()
        Deprecated.
        since 6.2.0 - usehasSessionCart()
      • calculateCart

        @Deprecated
        boolean calculateCart​(CartModel cartModel)
        Deprecated.
        since 6.2.0 - UseCalculationService.calculate(AbstractOrderModel) to calculate carts.
        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.
        Parameters:
        cartModel - the CartModel
        Returns:
        false if the cartModel was already calculated.
      • updateQuantities

        @Deprecated
        void updateQuantities​(CartModel cart,
                              java.util.List<java.lang.Long> quantities)
        Deprecated.
        since 6.2.0 - Update cart entries quantities directly viaAbstractOrderEntryModel.setQuantity(Long) or use updateQuantities(CartModel, Map)
        Updates the quantities of each cart entry with the list of quantities. If the quantity value is 0 the cart entry is removed.
        Parameters:
        cart - the cart where the quantities are updated
        quantities - the new quantity list for each cart entry
      • updateQuantities

        void updateQuantities​(CartModel cart,
                              java.util.Map<java.lang.Integer,​java.lang.Long> quantities)
        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.

        Parameters:
        cart - the cart to update cart entry quantities at
        quantities - the entry specific quantities as map of { entry number -> quantity }
      • appendToCart

        void appendToCart​(CartModel sourceCart,
                          CartModel targetCart)
        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.
        Parameters:
        sourceCart - the cart providing the entries to copy
        targetCart - the target cart to create new entries for
        Throws:
        java.lang.IllegalArgumentException - if targetCart is null.
      • changeCurrentCartUser

        void changeCurrentCartUser​(UserModel user)
        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.
        Parameters:
        user - new session cart user
        Throws:
        java.lang.IllegalArgumentException - when user is null
      • changeSessionCartCurrency

        void changeSessionCartCurrency​(CurrencyModel currency)
        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.
        Parameters:
        currency - new session cart currency
      • createCartFromQuote

        CartModel createCartFromQuote​(QuoteModel quote)
        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.
        Parameters:
        quote - the quote model
        Returns:
        the new cart model
        Throws:
        java.lang.IllegalArgumentException - when quote is null