Inheritance: ILocalizable
Exemplo n.º 1
0
        public ShoppingCartItem AddItem(ShoppingCart cart, Product product, ProductVariant productPrice, int quantity)
        {
            Require.NotNull(cart, "cart");
            Require.NotNull(product, "product");
            Require.NotNull(productPrice, "productPrice");
            Require.That(quantity > 0, "quantity", "Quantity should be greater than zero.");

            var item = cart.Items.FirstOrDefault(i => i.ProductVariant.Id == productPrice.Id);
            if (item == null)
            {
                item = new ShoppingCartItem(productPrice, quantity, cart);
                AddItem(cart, item);
            }
            else
            {
                ChangeItemQuantity(cart, item, item.Quantity + quantity);
            }

            return item;
        }
Exemplo n.º 2
0
        private void UpdateProduct(Product product, ProductEditorModel model)
        {
            product.Name = model.Name;
            product.Brand = model.Brand == null ? null : _brandService.Find(model.Brand.Id);

            product.Categories.Clear();
            foreach (var category in model.Categories)
            {
                product.Categories.Add(_categoryService.Find(category.Id));
            }

            product.SetCustomFields(model.CustomFields);
            product.SetImages(model.Images);

            foreach (var variant in product.Variants.ToList())
            {
                if (!model.Variants.Any(v => v.Id == variant.Id))
                {
                    product.Variants.Remove(variant);
                }
            }

            foreach (var variantModel in model.Variants)
            {
                ProductVariant variant;

                if (variantModel.Id > 0)
                {
                    variant = product.Variants.FirstOrDefault(v => v.Id == variantModel.Id);
                }
                else
                {
                    variant = new ProductVariant();
                    product.Variants.Add(variant);
                }

                variant.Sku = variantModel.Sku;
                variant.Price = variantModel.Price;
                variant.SetVariantFields(variantModel.VariantFields);
            }
        }
Exemplo n.º 3
0
 public ShoppingCartItem(ProductVariant variant, int quantity, ShoppingCart cart)
 {
     ProductVariant = variant;
     Quantity = quantity;
     ShoppingCart = cart;
 }
Exemplo n.º 4
0
 public PriceCalculationItem AddItem(int itemId, ProductVariant productPrice, int quantity)
 {
     var retailPrice = GetFinalUnitPrice(productPrice.ProductId, productPrice.Id, productPrice.Price);
     var item = new PriceCalculationItem(itemId, productPrice.ProductId, productPrice.Id, retailPrice, quantity);
     Items.Add(item);
     return item;
 }