public void AddItem(Product product) { CartItem newItem = new CartItem(); newItem.Options = new List <CartItemOptionValue>(); newItem.Product = product; foreach (var option in product.Options) { CartItemOptionValue cartItemValue = new CartItemOptionValue(); cartItemValue.Option = option; cartItemValue.Value = option.Values.FirstOrDefault(v => v.Default == true); newItem.Options.Add(cartItemValue); } Items.Add(newItem); }
public void AddItem(Product product, IEnumerable <ProductOptionValue> options, string comment) { CartItem newItem = new CartItem(); newItem.Options = new List <CartItemOptionValue>(); newItem.Product = product; newItem.Comment = comment; foreach (var option in options) { CartItemOptionValue cartItemValue = new CartItemOptionValue(); cartItemValue.Option = option.ProductOption; cartItemValue.Value = option; newItem.Options.Add(cartItemValue); } Items.Add(newItem); }