Package org.salespointframework.order
Class Cart
java.lang.Object
org.salespointframework.order.Cart
Abstraction of a shopping cart.
- Author:
- Paul Henke, Oliver Gierke
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddItemsTo
(Order order) Adds all items currently contained in this cart to the givenOrder
.addOrUpdateItem
(Product product, double amount) addOrUpdateItem
(Product product, long amount) addOrUpdateItem
(Product product, Quantity quantity) void
clear()
Clears the cart.createOrderFor
(UserAccount user) Deprecated, for removal: This API element is subject to removal in a future version.createOrderFor
(UserAccount.UserAccountIdentifier identifier) Creates a new Order for the givenUserAccount.UserAccountIdentifier
from the currentCart
.Returns the CartItem for the given identifier.int
Returns the number of items currently in the cart.javax.money.MonetaryAmount
getPrice()
getQuantity
(Product product) getQuantity
(Product.ProductIdentifier identifier) Returns the quantity for the givenProduct.ProductIdentifier
currently contained in theCart
.boolean
isEmpty()
Returns whether theCart
is currently empty.iterator()
void
removeItem
(String identifier) Removes theCartItem
with the given identifier.int
size()
Returns the size of theCart
, in other words, the number of items in it.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
-
Constructor Details
-
Cart
public Cart()
-
-
Method Details
-
addOrUpdateItem
-
addOrUpdateItem
-
addOrUpdateItem
-
removeItem
Removes theCartItem
with the given identifier.- Parameters:
identifier
- must not be null.
-
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
Deprecated, for removal: This API element is subject to removal in a future version.since 9.0, usecreateOrderFor(UserAccountIdentifier)
instead.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
.
-
createOrderFor
Creates a new Order for the givenUserAccount.UserAccountIdentifier
from the currentCart
.- Parameters:
identifier
- must not be null.- Returns:
- a new Order for the current
Cart
and givenUserAccount.UserAccountIdentifier
.
-
getNumberOfItems
public int getNumberOfItems()Returns the number of items currently in the cart. Sums up the containedProduct
's units defaulting to a single unit in case theProduct
is not handled in units.- Returns:
- will never be null.
- Since:
- 7.5
- See Also:
-
getQuantity
- Parameters:
product
- must not be null.- Returns:
- will never be null.
- Since:
- 7.5
-
getQuantity
Returns the quantity for the givenProduct.ProductIdentifier
currently contained in theCart
.- Parameters:
identifier
- must not be null.- Returns:
- will never be null.
- Since:
- 7.5
-
size
public int size()Returns the size of theCart
, in other words, the number of items in it.- Returns:
- Since:
- 8.0.1
-
getPrice
public javax.money.MonetaryAmount getPrice() -
iterator
-
createOrderFor(UserAccountIdentifier)
instead.