Class Cart

    • Constructor Detail

      • Cart

        public Cart()
    • Method Detail

      • addOrUpdateItem

        public CartItem addOrUpdateItem​(Product product,
                                        long amount)
        Creates a CartItem for the given Product and amount. If a CartItem for the given Product already exists the Cart will be updated to reflect the combined Quantity for the backing CartItem.
        Parameters:
        product - must not be null.
        amount - must not be null.
        Returns:
      • addOrUpdateItem

        public CartItem addOrUpdateItem​(Product product,
                                        double amount)
        Creates a CartItem for the given Product and amount. If a CartItem for the given Product already exists the Cart will be updated to reflect the combined Quantity for the backing CartItem.
        Parameters:
        product - must not be null.
        amount - must not be null.
        Returns:
      • removeItem

        public Optional<CartItem> removeItem​(String identifier)
        Removes the CartItem 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 the Cart is currently empty.
        Specified by:
        isEmpty in interface org.springframework.data.util.Streamable<CartItem>
        Returns:
      • addItemsTo

        public Order addItemsTo​(Order order)
        Turns the current state of the cart into an Order.
        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 not OrderStatus.OPEN anymore.
      • createOrderFor

        public Order createOrderFor​(UserAccount user)
        Creates a new Order for the given UserAccount from the current Cart.
        Parameters:
        user - must not be null.
        Returns:
        a new Order for the current Cart and given UserAccount.
      • getPrice

        public javax.money.MonetaryAmount getPrice()