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 Order
addItemsTo(Order order)
Turns the current state of the cart into anOrder
.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.-
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 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
public CartItem addOrUpdateItem(Product product, long amount)
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
public CartItem addOrUpdateItem(Product product, double amount)
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
public Optional<CartItem> removeItem(String identifier)
Removes theCartItem
with 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 theCart
is currently empty.- Specified by:
isEmpty
in 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
Order
which all items in the card have been added to. - Throws:
IllegalStateException
- if the given Order is notOrderStatus.OPEN
anymore.
-
createOrderFor
public Order createOrderFor(UserAccount user)
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()
-
-