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) { } }
public abstract void Apply(ShoppingCart cart, VoucherAppliedDecorator voucher);
public override void Apply(ShoppingCart cart, VoucherAppliedDecorator voucher) { voucher.AppliedValue = (cart.CartNonDiscountedPriceExcludingGiftVouchers() > voucher.Value) ? voucher.Value : cart.CartNonDiscountedPriceExcludingGiftVouchers(); }