Example #1
0
        public virtual void AddItem(CartBase cart, Product product, int quantity, Price salePrice, bool isCustomerPriceApplied)
        {
            // TODO : Placer ces règles d'ajout dans SalesService
            // checker la possibilité d'ajout
            if (product.SaleMode == ProductSaleMode.NotSellable)
            {
                // TODO : Convert to throw exception
                Logger.Warn("Add not sellable product {0} in order cart", product.Code);
                return;
            }
            quantity = Math.Max(1, quantity);
            var existing = cart.Items.SingleOrDefault(i => i.Product.Id == product.Id);
            salePrice = GetPriceByQuantity(product, quantity, salePrice);

            if (product.SaleMode == ProductSaleMode.EndOfLife)
            {
                var productStockInfo = CatalogService.GetProductStockInfo(product);
                if (productStockInfo == null)
                {
                    // TODO : Convert to throw exception
                    Logger.Warn("Add end of life product {0} in order cart", product.Code);
                    return;
                }
                var q = quantity;
                if (existing != null)
                {
                    q = existing.Quantity + quantity;
                }
                if (productStockInfo.AvailableStock < q)
                {
                    // TODO : Convert to throw exception
                    Logger.Warn("Add end of life product {0} in order cart , quantity {1}", product.Code, quantity);
                    return;
                }
            }

            if (existing == null)
            {
                Logger.Info("Add product {0} quantity {1} cart {2}", product.Code, quantity, cart.Code);

                var cartItem = CreateCartItem();
                cartItem.Product = product;
                cartItem.Quantity = quantity;
                cartItem.SalePrice = salePrice;
                cartItem.SaleUnitValue = product.SaleUnitValue;
                cartItem.Packaging = product.Packaging.Value;
                cartItem.RecyclePrice = product.RecyclePrice;
                cartItem.IsCustomerPriceApplied = isCustomerPriceApplied;

                cart.Items.Add(cartItem);
                AddLastCartItem(cartItem);
            }
            else if (!existing.IsLocked)
            {
                Logger.Info("Update cartitem product {0} quantity {1} cart {2}", product.Code, quantity, cart.Code);
                existing.Quantity += quantity;
            }
        }
Example #2
0
 public virtual void Save(CartBase cart)
 {
     if (cart == null)
     {
         return;
     }
     CartRepository.Save(cart);
 }
Example #3
0
 public virtual void RemoveCart(CartBase cart)
 {
     Logger.Info("Delete ordercart {0}", cart.Code);
     CartRepository.Remove(cart);
 }
Example #4
0
 public virtual void RemoveItem(CartBase cart, int index)
 {
     if (cart == null)
     {
         return;
     }
     if (index >= cart.ItemCount)
     {
         return;
     }
     var item = cart.Items[index];
     Logger.Info("Delete cartitem product {0} cart {1}", item.Product.Code, cart.Code);
     cart.Items.Remove(item);
 }
Example #5
0
 public virtual void Clear(CartBase cart)
 {
     if (cart == null)
     {
         return;
     }
     Logger.Info("Empty cart {0}", cart.Code);
     cart.Items.Clear();
 }