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 Order
addItemsTo(Order order)
Adds all items currently contained in this cart to the givenOrder
.CartItem
addOrUpdateItem(Product product, double amount)
CartItem
addOrUpdateItem(Product product, long amount)
CartItem
addOrUpdateItem(Product product, Quantity quantity)
void
clear()
Clears the cart.Order
createOrderFor(UserAccount user)
Creates a new Order for the givenUserAccount
from the currentCart
.Optional<CartItem>
getItem(String identifier)
Returns the CartItem for the given identifier.javax.money.MonetaryAmount
getPrice()
boolean
isEmpty()
Returns whether theCart
is currently empty.Iterator<CartItem>
iterator()
Optional<CartItem>
removeItem(String identifier)
Removes theCartItem
with the given identifier.
-
Constructor Details
-
Cart
public Cart()
-
-
Method Details
-
addOrUpdateItem
Creates aCartItem
for the givenProduct
andQuantity
. If aCartItem
for the givenProduct
already exists theCart
will be updated to reflect the combinedQuantity
for the backingCartItem
.- Parameters:
product
- must not be nullquantity
- must not be null- Returns:
- The created
CartItem
.
-
addOrUpdateItem
Creates aCartItem
for the givenProduct
and amount. If aCartItem
for the givenProduct
already exists theCart
will be updated to reflect the combinedQuantity
for the backingCartItem
.- Parameters:
product
- must not be null.amount
- must not be null.- Returns:
-
addOrUpdateItem
Creates aCartItem
for the givenProduct
and amount. If aCartItem
for the givenProduct
already exists theCart
will be updated to reflect the combinedQuantity
for the backingCartItem
.- Parameters:
product
- must not be null.amount
- must not be null.- Returns:
-
removeItem
Removes theCartItem
with 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 theCart
is currently empty.- Specified by:
isEmpty
in interfaceStreamable<CartItem>
- Returns:
-
addItemsTo
Adds all items currently contained in this cart to the givenOrder
.- Parameters:
order
- must not be null.- Returns:
- the
Order
with the added items of this cart - Throws:
IllegalStateException
- if the given Order is notOrderStatus.OPEN
anymore.
-
createOrderFor
Creates a new Order for the givenUserAccount
from the currentCart
.- Parameters:
user
- must not be null.- Returns:
- a new Order for the current
Cart
and givenUserAccount
.
-
getPrice
public javax.money.MonetaryAmount getPrice() -
iterator
-