예제 #1
0
        public void ApplyVoucher(IVoucher voucher)
        {
            try
            {
                if (!voucher.CanBeAppliedToCart(Cart))
                {
                    return;
                }

                var appliedVoucher = new VoucherAppliedDecorator(voucher);
                appliedVoucher.Apply(Cart);

                Cart.Vouchers.Add(appliedVoucher);
            }
            catch (OfferVoucherBasketTotalTooLowException exception)
            {
                Cart.Message =
                    $"You have not reached the spend threshold for voucher {voucher.Code}. Spend another £{exception.AmountToSpendStill} to receive £{voucher.Value} discount from your basket total.";
            }
            catch (VoucherDoesNotContainProductCategoryException exception)
            {
                Cart.Message = $"There are no products in your basket applicable to Voucher {voucher.Code} .";
            }
            catch (GiftVoucherBasketTotalTooLowException exception)
            {
                Cart.Message = $"There are no items in your basket applicable to Voucher {voucher.Code} .";
            }
            catch (Exception exception)
            {
            }
        }
예제 #2
0
 public abstract void Apply(ShoppingCart cart, VoucherAppliedDecorator voucher);
예제 #3
0
 public override void Apply(ShoppingCart cart, VoucherAppliedDecorator voucher)
 {
     voucher.AppliedValue = (cart.CartNonDiscountedPriceExcludingGiftVouchers() > voucher.Value)
                         ? voucher.Value
                         : cart.CartNonDiscountedPriceExcludingGiftVouchers();
 }