Package org.salespointframework.order
Class Cart
- java.lang.Object
-
- org.salespointframework.order.Cart
-
-
Constructor Summary
Constructors Constructor Description Cart()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OrderaddItemsTo(Order order)Turns the current state of the cart into anOrder.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
addOrUpdateItem
public CartItem addOrUpdateItem(Product product, Quantity quantity)
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
public CartItem addOrUpdateItem(Product product, long amount)
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
public CartItem addOrUpdateItem(Product product, double amount)
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
public Optional<CartItem> removeItem(String identifier)
Removes theCartItemwith the given identifier.- Parameters:
identifier- must not be null.- Returns:
-
getItem
public Optional<CartItem> getItem(String identifier)
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 interfaceorg.springframework.data.util.Streamable<CartItem>- Returns:
-
addItemsTo
public Order addItemsTo(Order order)
Turns the current state of the cart into anOrder.- Parameters:
order- must not be null.- Returns:
- the
Orderwhich all items in the card have been added to. - Throws:
IllegalStateException- if the given Order is notOrderStatus.OPENanymore.
-
createOrderFor
public Order createOrderFor(UserAccount user)
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()
-
-