more changes
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 36s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m59s

This commit is contained in:
matst80
2025-12-01 20:15:48 +01:00
parent c227870f13
commit 060b3dfbf0
22 changed files with 316 additions and 242 deletions

View File

@@ -2,6 +2,7 @@ package cart
import (
"context"
"errors"
"fmt"
"log"
"time"
@@ -16,13 +17,14 @@ import (
// This replaces the legacy switch-based logic previously found in CartGrain.Apply.
//
// Behavior:
// * Validates quantity > 0
// * If an item with same SKU exists -> increases quantity
// * Else creates a new CartItem with computed tax amounts
// * Totals recalculated automatically via WithTotals()
// - Validates quantity > 0
// - If an item with same SKU exists -> increases quantity
// - Else creates a new CartItem with computed tax amounts
// - Totals recalculated automatically via WithTotals()
//
// NOTE: Any future field additions in messages.AddItem that affect pricing / tax
// must keep this handler in sync.
var ErrPaymentInProgress = errors.New("payment in progress")
func (c *CartMutationContext) AddItem(g *CartGrain, m *messages.AddItem) error {
ctx := context.Background()
@@ -32,6 +34,9 @@ func (c *CartMutationContext) AddItem(g *CartGrain, m *messages.AddItem) error {
if m.Quantity < 1 {
return fmt.Errorf("AddItem: invalid quantity %d", m.Quantity)
}
if g.PaymentInProgress > 0 {
return ErrPaymentInProgress
}
// Merge with any existing item having same SKU and matching StoreId (including both nil).
for _, existing := range g.Items {