Пример #1
0
        /// <summary>
        /// Adds to shopping cart.
        /// </summary>
        /// <param name="productCode">The product code.</param>
        /// <param name="quantity">The quantity.</param>
        public virtual void AddProduct(string productCode, uint quantity)
        {
            Assert.ArgumentNotNullOrEmpty(productCode, "productCode");
            if (quantity == 0)
            {
                return;
            }

            DomainModel.Carts.ShoppingCartLine existingShoppingCartLine = this.shoppingCart.ShoppingCartLines.FirstOrDefault(p => p.Product.Code.Equals(productCode));

            if (existingShoppingCartLine != null)
            {
                existingShoppingCartLine.Quantity += quantity;
                existingShoppingCartLine.Totals    = this.productPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(existingShoppingCartLine.Product, this.shoppingCart.Currency, existingShoppingCartLine.Quantity);
            }
            else
            {
                existingShoppingCartLine = Context.Entity.Resolve <DomainModel.Carts.ShoppingCartLine>();

                ProductBaseData product = this.productRepository.Get <ProductBaseData>(productCode);
                Assert.IsNotNull(product, "Unable to add product \"{0}\" to the shopping cart. The product is not found.", productCode);

                existingShoppingCartLine.Product  = product;
                existingShoppingCartLine.Quantity = quantity;

                existingShoppingCartLine.Totals = this.productPriceManager.GetProductTotals <Totals, ProductBaseData, Currency>(product, this.shoppingCart.Currency, existingShoppingCartLine.Quantity);

                this.shoppingCart.ShoppingCartLines.Add(existingShoppingCartLine);
            }

            Context.Entity.SetInstance(this.shoppingCart);
        }
Пример #2
0
        /// <summary>
        /// Removes the product line from shopping cart.
        /// </summary>
        /// <param name="productCode">The product code.</param>
        public virtual void RemoveProductLine(string productCode)
        {
            Assert.ArgumentNotNullOrEmpty(productCode, "productCode");

            DomainModel.Carts.ShoppingCartLine existingShoppingCartLine = this.shoppingCart.ShoppingCartLines.FirstOrDefault(p => p.Product.Code.Equals(productCode));

            if (existingShoppingCartLine == null)
            {
                return;
            }

            this.shoppingCart.ShoppingCartLines.Remove(existingShoppingCartLine);

            Context.Entity.SetInstance(this.shoppingCart);
        }