public CartItemAdded(ShoppingCart cart, ShoppingCartItem item) { CartId = cart.Id; ItemId = item.Id; ProductId = item.ProductVariant.ProductId; ProductPriceId = item.ProductVariant.Id; Quantity = item.Quantity; }
public CartItemQuantityChanged(ShoppingCart cart, ShoppingCartItem item, int oldQuantity) { CartId = cart.Id; ItemId = item.Id; ProductId = item.ProductVariant.ProductId; ProductPriceId = item.ProductVariant.Id; OldQuantity = oldQuantity; NewQuantity = item.Quantity; }
public void AddItem(ShoppingCart cart, ShoppingCartItem item) { Require.NotNull(cart, "cart"); Require.NotNull(item, "item"); cart.Items.Add(item); _repository.Database.SaveChanges(); Event.Raise(new CartItemAdded(cart, item), _instance); }
public static OrderItem CreateFrom(ShoppingCartItem cartItem, decimal finalUnitPrice) { return new OrderItem { ProductVariantId = cartItem.ProductVariant.Id, ProductVariant = cartItem.ProductVariant, Sku = cartItem.ProductVariant.Sku, UnitPrice = finalUnitPrice, Quantity = cartItem.Quantity }; }
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; }
public void ChangeItemQuantity(ShoppingCart cart, ShoppingCartItem item, int newQuantity) { Require.NotNull(cart, "cart"); Require.NotNull(item, "item"); Require.That(newQuantity > 0, "newQuantity", "Quantity should be greater than zero."); if (item.Quantity != newQuantity) { var oldQuantity = item.Quantity; item.Quantity = newQuantity; _repository.Database.SaveChanges(); Event.Raise(new CartItemQuantityChanged(cart, item, oldQuantity), _instance); } }