Ejemplo n.º 1
0
        public void Add(int productId, int quantity = 1)
        {
            // only add if in stock: removed from stock when order processed (
            var product = GetProduct(productId);

            if (!product.UseStockControl || (product != null && product.InStock > 0))
            {
                var item = Items.SingleOrDefault(x => x.ProductId == productId);

                if (item == null)
                {
                    item = new ShoppingCartItem(productId, quantity);
                    ItemsInternal.Add(item);

                    // add the default shipping 'product' to cover packing and shipping costs
                    var shippingProductId = _webshopSettings.GetShippingProductRecordId();
                    if (shippingProductId > 0 && product.IsShippable && !ItemsInternal.Exists(i => i.ProductId == shippingProductId))
                    {
                        ItemsInternal.Add(new ShoppingCartItem(shippingProductId, 1));
                    }
                }


                // DG: Comment this out to limit to one item (because it's easy to click 'Add' multiple times)
                // TODO: make it a setting
                else
                {
                    item.Quantity += quantity;
                }
            }
        }