예제 #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;
            }
        }
예제 #2
0
 private Price GetPriceByQuantity(Product product, int quantity, Price defaultSalePrice)
 {
     Price result = defaultSalePrice;
     if (product.PriceByQuantityList.IsNotNullOrEmpty())
     {
         var price = product.PriceByQuantityList.First(i => quantity >= i.From
                                                         && quantity < i.To.GetValueOrDefault(int.MaxValue));
         if (price != null)
         {
             result = price.SalePrice;
         }
     }
     return result;
 }