Class CartServiceImpl

java.lang.Object
com.jahnreil_stratpoint.service.CartServiceImpl
All Implemented Interfaces:
ICartService

public class CartServiceImpl extends Object implements ICartService
Implementation of the ICartService interface, providing services for managing the shopping cart.
  • Constructor Details

    • CartServiceImpl

      public CartServiceImpl()
  • Method Details

    • addToCart

      public Cart addToCart(Product product, Cart cart)
      Adds a product to the cart. If the product is already in the cart, increases its quantity.
      Specified by:
      addToCart in interface ICartService
      Parameters:
      product - the product to add
      cart - the cart to which the product is added
      Returns:
      the updated cart
    • findItem

      public Optional<CartItem> findItem(Cart cart, Product product)
      Finds an item in the cart based on the product.
      Specified by:
      findItem in interface ICartService
      Parameters:
      cart - the cart to search
      product - the product to find
      Returns:
      an optional containing the found cart item, or empty if not found
    • findCartItemById

      public static CartItem findCartItemById(int id)
      Finds a cart item by its product ID.
      Parameters:
      id - the product ID
      Returns:
      the found cart item, or null if not found
    • addCartItemToCart

      public Cart addCartItemToCart(CartItem cartItem, Cart cart)
      Adds a cart item to the cart.
      Specified by:
      addCartItemToCart in interface ICartService
      Parameters:
      cartItem - the cart item to add
      cart - the cart to which the item is added
      Returns:
      the updated cart
    • removeCartItemFromCart

      public Cart removeCartItemFromCart(CartItem cartItem, Cart cart)
      Removes a cart item from the cart.
      Specified by:
      removeCartItemFromCart in interface ICartService
      Parameters:
      cartItem - the cart item to remove
      cart - the cart from which the item is removed
      Returns:
      the updated cart
    • decreaseCartItemFromItems

      public Cart decreaseCartItemFromItems(Cart cart, Product product)
      Decreases the quantity of a product in the cart. If the quantity reaches 0, removes the item from the cart.
      Specified by:
      decreaseCartItemFromItems in interface ICartService
      Parameters:
      cart - the cart
      product - the product to decrease the quantity of
      Returns:
      the updated cart
    • getaCartItemTotal

      public static BigDecimal getaCartItemTotal(CartItem cartItem)
      Gets the total price of a cart item.
      Parameters:
      cartItem - the cart item
      Returns:
      the total price of the cart item
    • updateCartItemTotal

      public static BigDecimal updateCartItemTotal(ArrayList<CartItem> cartItems)
      Updates the total price of all cart items.
      Parameters:
      cartItems - the cart items
      Returns:
      the updated total price
    • getCartItemsTotal

      public static BigDecimal getCartItemsTotal()
      Gets the total price of all items in the cart.
      Returns:
      the total price of all items in the cart
    • checkout

      public void checkout()
      Checks out the cart.
      Specified by:
      checkout in interface ICartService