Interface CartService

All Superinterfaces:
AbstractOrderService<CartModel,CartEntryModel>
All Known Subinterfaces:
B2BCartService
All Known Implementing Classes:
DefaultB2BCartService, DefaultCartService, DefaultCartServiceForAccelerator

public interface CartService extends AbstractOrderService<CartModel,CartEntryModel>
Service providing cart oriented functionality. On contrary to order, cart does not represent a legal contract with the customer, but similarly to OrderModel, CartModel is a subtype of AbstractOrderModel, so the service fulfills the contract of AbstractOrderService for the CartModel and CartEntryModel types. Additionally it provides methods for handling the session cart.
Spring Bean ID:
cartService
  • Method Details

    • addToCart

      @Deprecated(since="6.2.0", forRemoval=true) void addToCart(CartModel cart, ProductModel product, long quantity, UnitModel unit) throws InvalidCartException
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 6.2.0 - UseAbstractOrderService.addNewEntry(AbstractOrderModel, ProductModel, long, UnitModel) from the cart service instead. Please mind the fact that AbstractOrderService.addNewEntry(AbstractOrderModel, ProductModel, long, UnitModel) method does not calculate or save the cart.
      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.
      Parameters:
      cart - the cart, must exist
      product - the product which is added to the cart
      quantity - the quantity of the product
      unit - 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)
    • 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:
    • 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:
    • hasCart

      @Deprecated(since="6.2.0", forRemoval=true) boolean hasCart()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 6.2.0 - usehasSessionCart()
    • calculateCart

      @Deprecated(since="6.2.0", forRemoval=true) boolean calculateCart(CartModel cartModel)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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(since="6.2.0", forRemoval=true) void updateQuantities(CartModel cart, List<Long> quantities)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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, Map<Integer,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:
      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:
      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:
      IllegalArgumentException - when quote is null