// 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;
        }
        // Side effect free function
        public BasketPricingBreakdown calculate_total_price_for(Guid basket_id)
        {
            var basketPricingBreakdown = new BasketPricingBreakdown();
            var basket = _basketRepository.find_by(basket_id);
            var basket_discount = new Money();
            var coupon_issue = CouponIssues.NotApplied;

            if (basket.has_had_coupon_applied())
            {
                var coupon = _offerRepository.find_by(basket.coupon_id);

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

            basketPricingBreakdown.basket_total = basket.items_total;
            basketPricingBreakdown.discount = basket_discount;
            basketPricingBreakdown.coupon_message = coupon_issue;

            return basketPricingBreakdown;
        }
Beispiel #3
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);
        }