public override DiscountBase GetDiscountStrategy(Basket basket, DiscountBase parentDiscountStrategy = null)
        {
            DiscountBase bestStrategy = null;
            double       bestPrice    = 0;
            //Product Discount + MembershipDiscount
            DiscountBase productDiscount = new ProductDiscount(true);
            DiscountBase membershipAndProductDiscount = BasketDiscountOverMemberShipFactory.Instance.GetDiscountStrategy(basket, productDiscount);

            bestStrategy = membershipAndProductDiscount;
            bestPrice    = membershipAndProductDiscount.GetDiscountedTotal(basket);

            //Basket Discount + MembershipDiscount
            DiscountBase basketDiscount = BasketDiscountOverTotalFactory.Instance.GetDiscountStrategy(basket, null);
            DiscountBase memberShipAndBasketDiscount = BasketDiscountOverMemberShipFactory.Instance.GetDiscountStrategy(basket, basketDiscount);

            (bestPrice, bestStrategy) = GetBetterStrategy(bestPrice, bestStrategy, basket, memberShipAndBasketDiscount);
            //Product Discount + CategoryDiscount + MembershipDiscount
            DiscountBase categoryAndProductDiscount          = CategoryDiscountFactory.Instance.GetDiscountStrategy(basket, productDiscount);
            DiscountBase membershipCategoryAndProdutDiscount = BasketDiscountOverMemberShipFactory.Instance.GetDiscountStrategy(basket, categoryAndProductDiscount);

            (bestPrice, bestStrategy) = GetBetterStrategy(bestPrice, bestStrategy, basket, membershipCategoryAndProdutDiscount);
            //Special Offer Basket Discount (like BlackFriday)

            DiscountBase blackFridayDiscountStrategy = BlackFridayDiscountFactory.Instance.GetDiscountStrategy(basket, null);

            (bestPrice, bestStrategy) = GetBetterStrategy(bestPrice, bestStrategy, basket, blackFridayDiscountStrategy);
            return(bestStrategy);
        }
示例#2
0
 protected virtual (double price, DiscountBase) GetBetterStrategy(double discountedPrice, DiscountBase currentStragey, Basket basket, DiscountBase nextDiscountStrategy)
 {
     if (nextDiscountStrategy != null)
     {
         double nextPrice = nextDiscountStrategy.GetDiscountedTotal(basket);
         if (currentStragey == null || nextPrice < discountedPrice)
         {
             return(nextPrice, nextDiscountStrategy);
         }
     }
     return(discountedPrice, currentStragey);
 }
示例#3
0
        public override DiscountBase GetDiscountStrategy(Basket basket, DiscountBase parentDiscountStrategy)
        {
            DiscountBase bestStrategy = null;
            double       bestPrice    = 0;

            foreach (KeyValuePair <DiscountTypesEnum, Func <DiscountBase, DiscountBase> > discountStrategy in BasketDiscountOverMemberShipFactory.Creators)
            {
                DiscountBase currentStrategy = discountStrategy.Value(parentDiscountStrategy);
                if (currentStrategy.IsEnabled(basket) &&
                    (bestStrategy == null || bestStrategy.GetDiscountedTotal(basket) > currentStrategy.GetDiscountedTotal(basket)))
                {
                    (bestPrice, bestStrategy) = this.GetBetterStrategy(bestPrice, bestStrategy, basket, currentStrategy);
                }
            }
            return(bestStrategy);
        }
示例#4
0
 public double calcDiscountedTotal(DiscountBase discountStrategy)
 {
     DiscountedTotal = discountStrategy.GetDiscountedTotal(this);
     return(DiscountedTotal);
 }