voucher saftey

This commit is contained in:
matst80
2025-10-14 23:17:32 +02:00
parent f5014fe906
commit 4835041f14
2 changed files with 4 additions and 1 deletions

View File

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

View File

@@ -21,7 +21,6 @@ type Voucher struct {
type Service struct {
// Add fields here
}
var ErrInvalidCode = errors.New("invalid vouchercode")