3 Commits

Author SHA1 Message Date
matst80
47adb12112 Merge branch 'main' of git-ssh.tornberg.me:mats/go-cart-actor
All checks were successful
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m22s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m1s
2025-10-14 23:24:29 +02:00
matst80
4835041f14 voucher saftey 2025-10-14 23:17:32 +02:00
104f9fbb4c missing updates (#5)
All checks were successful
Build and Publish / Metadata (push) Successful in 8s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m23s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m16s
Co-authored-by: matst80 <mats.tornberg@gmail.com>
Reviewed-on: https://git.tornberg.me/mats/go-cart-actor/pulls/5
Co-authored-by: Mats Törnberg <mats@tornberg.me>
Co-committed-by: Mats Törnberg <mats@tornberg.me>
2025-10-14 23:12:01 +02:00
3 changed files with 10 additions and 3 deletions

View File

@@ -260,6 +260,10 @@ func (c *CartGrain) UpdateTotals() {
for _, voucher := range c.Vouchers { for _, voucher := range c.Vouchers {
if _, ok := voucher.AppliesTo(c); ok { if _, ok := voucher.AppliesTo(c); ok {
value := NewPriceFromIncVat(voucher.Value, 25) 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.TotalDiscount.Add(*value)
c.TotalPrice.Subtract(*value) c.TotalPrice.Subtract(*value)

View File

@@ -30,9 +30,13 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
// Fast path: merge with existing item having same SKU // Fast path: merge with existing item having same SKU
if existing, found := g.FindItemWithSku(m.Sku); found { if existing, found := g.FindItemWithSku(m.Sku); found {
if existing.StoreId == m.StoreId {
existing.Quantity += int(m.Quantity) existing.Quantity += int(m.Quantity)
existing.Stock = StockStatus(m.Stock)
existing.StoreId = m.StoreId
return nil return nil
} }
}
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()

View File

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