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")