// 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;
        }
 public BasketItem(Product product, NonNegativeQuantity quantity)
 {
     _id = Guid.NewGuid();
     _price = product.price;
     _product_id = product.id;
     _quantity = quantity;
 }
        // 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;
        }
Exemple #4
0
 public Promotion(string voucher_code, Money discount, Money threshold)
 {
     // TODO: Check for null values and invalid data
     _voucher_code = voucher_code;
     _discount = discount;
     _threshold = threshold;
 }
 public Product(int id, string name, Money price, string category)
 {
     // TODO: Check for null values and invalid data
     _id = id;
     _name = name;
     _price = price;
     _category = category;
 }
 public BasketVoucher(Guid basket_id, string voucher_code, Money discount, Money threshold)
 {
     _id = Guid.NewGuid();
     _basket_id = basket_id;
     _voucher_code = voucher_code;
     _discount = discount;
     _threshold = threshold;
 }
 public Offer(string voucher_code, Money discount, Money threshold)
     : this()
 {
     // TODO: Check for null values and invalid data
     _voucher_code = voucher_code;
     _discount = discount;
     _threshold = threshold;
 }
        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;
        }
 private Money calculate_cost_with_discount_of(Money discount)
 {
     return items_total.minus(discount);
 }
        private Money caclulate_basket_discount()
        {
            Money _discount = new Money();
            if (_basket_voucher != null)
                _discount = _basket_voucher.calculate_discount_for(this);

            return _discount;
        }
 public BasketPriceChanged(Guid basket_id, Money cost_of_basket)
 {
     this.basket_id = basket_id;
     CostOfBasket = cost_of_basket;
 }
Exemple #12
0
 public BasketPriceChanged(Guid basket_id, Money cost_of_basket, Money discount)
 {
     this.basket_id = basket_id;
     CostOfBasket = cost_of_basket;
     Discount = discount;
 }
Exemple #13
0
 public BasketCreated(Guid id, Money amountToPay)
 {
     Id = id;
     AmountToPay = amountToPay;
 }