Esempio n. 1
0
        /// <summary>
        /// Adds a product to the cart
        /// </summary>
        public void AddItem(Product product, int quantity, DateTime dateAdded)
        {
            //see if this item is in the cart already
            ShoppingCartItem item = FindItem(product);

            if (quantity != 0) {
                if (item != null) {
                    //if the passed in amount is 0, do nothing
                    //as we're assuming "add 0 of this item" means
                    //do nothing
                    if (quantity != 0)
                        AdjustQuantity(product, item.Quantity);
                } else {
                    if (quantity > 0) {
                        item = new ShoppingCartItem(product, quantity, dateAdded);

                        //add to list
                        Items.Add(item);
                    }
                }

            }
        }
Esempio n. 2
0
        public void AddLineItem(ShoppingCartItem cartItem)
        {
            if (cartItem.Product == null)
                throw new InvalidOperationException(Messages.NullCartItemProduct);

            Product item = cartItem.Product;

            if (CurrentState.CanChangeItems) {
                OrderLine lineItem = new OrderLine(cartItem.DateAdded,cartItem.Quantity,item);
                this.Items.Add(lineItem);
            }
        }
        /// <summary>
        /// Adjusts the quantity of an item in the cart
        /// </summary>
        public void AdjustQuantity(string sku, int newQuantity)
        {
            ShoppingCartItem itemToAdjust = FindItem(sku);

            AdjustQuantity(itemToAdjust.Product, newQuantity);
        }