Esempio n. 1
0
        // Side effect free function
        public BasketPricingBreakdown calculate_total_price_for(IEnumerable<BasketItem> items, IEnumerable<Coupon> coupons)
        {
            var basketPricingBreakdown = new BasketPricingBreakdown();
            var basket_discount = new Money();
            var coupon_issue = CouponIssues.NotApplied;

            //foreach (var coupon in coupons)
            //{
            //    // 1. Get all coupons associted with the basket
            //    // 2. Check if it is applicable or which one wins.
            //    var promotion = _promotions_repository.find_by(coupon.code);

            //    if (promotion.is_still_active() && promotion.can_be_applied_to(basket))
            //    {
            //        basket_discount = promotion.calculate_discount_for(items);
            //        coupon_issue = CouponIssues.NoIssue;
            //    }
            //    else
            //    {
            //        coupon_issue = coupon.reason_why_cannot_be_applied_to(items);
            //    }
            //}

            var total = new Money();
            foreach(var item in items)
            {
                total = total.add(item.line_total());
            }

            basketPricingBreakdown.basket_total = total;
            basketPricingBreakdown.discount = basket_discount;
            basketPricingBreakdown.coupon_message = coupon_issue;

            return basketPricingBreakdown;
        }
        public Money calculate_discount_for(Basket basket)
        {
            var discount = new Money();

            if (this.meets_criteria_for_discount(basket))
            {
                discount = discount.add(_discount);
            }
            else
            {
                determine_why_not_applicable_for(basket); // This sets why the voucher is not applicable
            }

            return discount;
        }