Exemple #1
0
        /// <summary>
        /// Method used to create total price for the products.
        /// </summary>
        /// <param name="products">The cart items.</param>
        /// <returns>Returns total price.</returns>
        public int CalculateTotalPrice(List <char> products)
        {
            try
            {
                if (cartEngine != null)
                {
                    //// Step 1 : Apply promotions for orders
                    if (promotionEngine != null)
                    {
                        int promotionTotalPrice = promotionEngine.ApplyPromotion(products);

                        //// Calculate billing for the non promoted items.
                        int cartProductTotalPrice = cartEngine.Calculate(promotionEngine.GetNonPromotedItems(products));
                        return(promotionTotalPrice + cartProductTotalPrice);
                    }

                    //// step 2 : Calculate non promotion type if it is exists else calculate complete orders
                    return(cartEngine.Calculate(products));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(0);
        }
Exemple #2
0
 public int CheckoutCart(Cart cart)
 {
     if (promotionEngine != null)
     {
         var discountPrice = promotionEngine.ApplyPromotion(cart);
         return(discountPrice);
     }
     return(0);
 }
Exemple #3
0
        private static void Checkout(char[] v)
        {
            var priceAfterPromotion = _promotionEngine.ApplyPromotion(v);

            foreach (var item in priceAfterPromotion.RemainingProducts)
            {
                priceAfterPromotion.PromotedProductsPrice += _productCatalog.GetPrice(item);
            }

            Console.WriteLine("Total Price: {0}", priceAfterPromotion.PromotedProductsPrice);
        }