Class DefaultCartService

All Implemented Interfaces:
AbstractOrderService<CartModel,CartEntryModel>, CartService, Serializable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
DefaultB2BCartService, DefaultCartServiceForAccelerator

public class DefaultCartService extends DefaultAbstractOrderService<CartModel,CartEntryModel> implements CartService
Default implementation of the CartService
See Also:
  • Field Details

  • Constructor Details

    • DefaultCartService

      public DefaultCartService()
  • Method Details

    • addToCart

      @Deprecated(since="6.2.0", forRemoval=true) public void addToCart(CartModel cartModel, ProductModel productModel, long quantity, UnitModel unitModel) throws InvalidCartException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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)
    • hasSessionCart

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

      @Deprecated(since="6.2.0", forRemoval=true) public boolean hasCart()
      Deprecated, for removal: This API element is subject to removal in a future version.
      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(since="6.2.0", forRemoval=true) public boolean calculateCart(CartModel cartModel)
      Deprecated, for removal: This API element is subject to removal in a future version.
      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(since="6.2.0", forRemoval=true) public 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
      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, Map<Integer,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 }
    • removeSessionCart

      public void removeSessionCart()
      Description copied from interface: CartService
      If existing the current session cart is being detached from this session and removed. Afterwards it's no longer available.
      Specified by:
      removeSessionCart in interface CartService
      See Also:
    • clone

      public CartModel clone(ComposedTypeModel orderType, ComposedTypeModel entryType, AbstractOrderModel original, String code)
      Description copied from interface: AbstractOrderService
      Creates new order from given original and change its type and type for entry. Delegates to the specific CloneAbstractOrderStrategy injected strategy. Resulting order remains not persisted.
      Specified by:
      clone in interface AbstractOrderService<CartModel,CartEntryModel>
      Parameters:
      orderType - type of result order (OrderModel will be chosen if null is passed)
      entryType - type of entry (if null will use service to get proper type)
      original - original order
      code - code for new order
      Returns:
      not persisted order model instance.
    • 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(Collection<CartEntryModel> sourceClones, int lastEntryNo, CartModel targetCart)
      Rearrange cloned entries numbers according to last entry number from the target.
    • getNextEntryNumber

      protected int getNextEntryNumber(CartModel cart, AbstractOrderEntryModel forMe)
    • 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
    • getCreateCartFromQuoteStrategy

      protected CreateCartFromQuoteStrategy getCreateCartFromQuoteStrategy()
    • setCreateCartFromQuoteStrategy

      public void setCreateCartFromQuoteStrategy(CreateCartFromQuoteStrategy createCartFromQuoteStrategy)