Package com.jahnreil_stratpoint.service
Class CartServiceImpl
java.lang.Object
com.jahnreil_stratpoint.service.CartServiceImpl
- All Implemented Interfaces:
ICartService
Implementation of the ICartService interface, providing services for managing the shopping cart.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddCartItemToCart
(CartItem cartItem, Cart cart) Adds a cart item to the cart.Adds a product to the cart.void
checkout()
Checks out the cart.decreaseCartItemFromItems
(Cart cart, Product product) Decreases the quantity of a product in the cart.static CartItem
findCartItemById
(int id) Finds a cart item by its product ID.Finds an item in the cart based on the product.static BigDecimal
getaCartItemTotal
(CartItem cartItem) Gets the total price of a cart item.static BigDecimal
Gets the total price of all items in the cart.removeCartItemFromCart
(CartItem cartItem, Cart cart) Removes a cart item from the cart.static BigDecimal
updateCartItemTotal
(ArrayList<CartItem> cartItems) Updates the total price of all cart items.
-
Constructor Details
-
CartServiceImpl
public CartServiceImpl()
-
-
Method Details
-
addToCart
Adds a product to the cart. If the product is already in the cart, increases its quantity.- Specified by:
addToCart
in interfaceICartService
- Parameters:
product
- the product to addcart
- the cart to which the product is added- Returns:
- the updated cart
-
findItem
Finds an item in the cart based on the product.- Specified by:
findItem
in interfaceICartService
- Parameters:
cart
- the cart to searchproduct
- the product to find- Returns:
- an optional containing the found cart item, or empty if not found
-
findCartItemById
Finds a cart item by its product ID.- Parameters:
id
- the product ID- Returns:
- the found cart item, or null if not found
-
addCartItemToCart
Adds a cart item to the cart.- Specified by:
addCartItemToCart
in interfaceICartService
- Parameters:
cartItem
- the cart item to addcart
- the cart to which the item is added- Returns:
- the updated cart
-
removeCartItemFromCart
Removes a cart item from the cart.- Specified by:
removeCartItemFromCart
in interfaceICartService
- Parameters:
cartItem
- the cart item to removecart
- the cart from which the item is removed- Returns:
- the updated cart
-
decreaseCartItemFromItems
Decreases the quantity of a product in the cart. If the quantity reaches 0, removes the item from the cart.- Specified by:
decreaseCartItemFromItems
in interfaceICartService
- Parameters:
cart
- the cartproduct
- the product to decrease the quantity of- Returns:
- the updated cart
-
getaCartItemTotal
Gets the total price of a cart item.- Parameters:
cartItem
- the cart item- Returns:
- the total price of the cart item
-
updateCartItemTotal
Updates the total price of all cart items.- Parameters:
cartItems
- the cart items- Returns:
- the updated total price
-
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 interfaceICartService
-