From 4835041f14685a81cffcd7c5b2147cca4a8dab82 Mon Sep 17 00:00:00 2001 From: matst80 Date: Tue, 14 Oct 2025 23:17:32 +0200 Subject: [PATCH] voucher saftey --- cmd/cart/cart-grain.go | 4 ++++ pkg/voucher/service.go | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/cart/cart-grain.go b/cmd/cart/cart-grain.go index 326f8e4..3448274 100644 --- a/cmd/cart/cart-grain.go +++ b/cmd/cart/cart-grain.go @@ -260,6 +260,10 @@ func (c *CartGrain) UpdateTotals() { for _, voucher := range c.Vouchers { if _, ok := voucher.AppliesTo(c); ok { value := NewPriceFromIncVat(voucher.Value, 25) + if c.TotalPrice.IncVat <= value.IncVat { + // don't apply discounts to more than the total price + continue + } c.TotalDiscount.Add(*value) c.TotalPrice.Subtract(*value) diff --git a/pkg/voucher/service.go b/pkg/voucher/service.go index fb14ef4..d75877e 100644 --- a/pkg/voucher/service.go +++ b/pkg/voucher/service.go @@ -21,7 +21,6 @@ type Voucher struct { type Service struct { // Add fields here - } var ErrInvalidCode = errors.New("invalid vouchercode")