Package org.salespointframework.order
Class Cart
java.lang.Object
org.salespointframework.order.Cart
public class Cart extends Object implements Streamable<CartItem>
Abstraction of a shopping cart.
- Author:
- Paul Henke, Oliver Gierke
-
Constructor Summary
Constructors Constructor Description Cart() -
Method Summary
Modifier and Type Method Description OrderaddItemsTo(Order order)Adds all items currently contained in this cart to the givenOrder.CartItemaddOrUpdateItem(Product product, double amount)CartItemaddOrUpdateItem(Product product, long amount)CartItemaddOrUpdateItem(Product product, Quantity quantity)voidclear()Clears the cart.OrdercreateOrderFor(UserAccount user)Creates a new Order for the givenUserAccountfrom the currentCart.Optional<CartItem>getItem(String identifier)Returns the CartItem for the given identifier.javax.money.MonetaryAmountgetPrice()booleanisEmpty()Returns whether theCartis currently empty.Iterator<CartItem>iterator()Optional<CartItem>removeItem(String identifier)Removes theCartItemwith the given identifier.
-
Constructor Details
-
Cart
public Cart()
-
-
Method Details
-
addOrUpdateItem
Creates aCartItemfor the givenProductandQuantity. If aCartItemfor the givenProductalready exists theCartwill be updated to reflect the combinedQuantityfor the backingCartItem.- Parameters:
product- must not be nullquantity- must not be null- Returns:
- The created
CartItem.
-
addOrUpdateItem
Creates aCartItemfor the givenProductand amount. If aCartItemfor the givenProductalready exists theCartwill be updated to reflect the combinedQuantityfor the backingCartItem.- Parameters:
product- must not be null.amount- must not be null.- Returns:
-
addOrUpdateItem
Creates aCartItemfor the givenProductand amount. If aCartItemfor the givenProductalready exists theCartwill be updated to reflect the combinedQuantityfor the backingCartItem.- Parameters:
product- must not be null.amount- must not be null.- Returns:
-
removeItem
Removes theCartItemwith the given identifier.- Parameters:
identifier- must not be null.- Returns:
-
getItem
Returns the CartItem for the given identifier.- Parameters:
identifier- must not be null.- Returns:
-
clear
public void clear()Clears the cart. -
isEmpty
public boolean isEmpty()Returns whether theCartis currently empty.- Specified by:
isEmptyin interfaceStreamable<CartItem>- Returns:
-
addItemsTo
Adds all items currently contained in this cart to the givenOrder.- Parameters:
order- must not be null.- Returns:
- the
Orderwith the added items of this cart - Throws:
IllegalStateException- if the given Order is notOrderStatus.OPENanymore.
-
createOrderFor
Creates a new Order for the givenUserAccountfrom the currentCart.- Parameters:
user- must not be null.- Returns:
- a new Order for the current
Cartand givenUserAccount.
-
getPrice
public javax.money.MonetaryAmount getPrice() -
iterator
-