Ejemplo n.º 1
0
 public CartItemAdded(ShoppingCart cart, ShoppingCartItem item)
 {
     CartId = cart.Id;
     ItemId = item.Id;
     ProductId = item.ProductVariant.ProductId;
     ProductPriceId = item.ProductVariant.Id;
     Quantity = item.Quantity;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 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
     };
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        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);
            }
        }