add giftcards

This commit is contained in:
matst80
2025-11-21 10:14:33 +01:00
parent 896bf7672b
commit 886e3ce48f
7 changed files with 374 additions and 16 deletions

View File

@@ -89,17 +89,29 @@ type Marking struct {
Text string `json:"text"`
}
type GiftcardItem struct {
Id uint32 `json:"id"`
Value Price `json:"value"`
DeliveryDate string `json:"deliveryDate"`
Recipient string `json:"recipient"`
RecipientType string `json:"recipientType"`
Message string `json:"message"`
DesignConfig json.RawMessage `json:"designConfig,omitempty"`
}
type CartGrain struct {
mu sync.RWMutex
lastItemId uint32
lastDeliveryId uint32
lastVoucherId uint32
lastGiftcardId uint32
lastAccess time.Time
lastChange time.Time // unix seconds of last successful mutation (replay sets from event ts)
userId string
InventoryReserved bool `json:"inventoryReserved"`
Id CartId `json:"id"`
Items []*CartItem `json:"items"`
Giftcards []*GiftcardItem `json:"giftcards,omitempty"`
TotalPrice *Price `json:"totalPrice"`
TotalDiscount *Price `json:"totalDiscount"`
Deliveries []*CartDelivery `json:"deliveries,omitempty"`
@@ -185,11 +197,13 @@ func NewCartGrain(id uint64, ts time.Time) *CartGrain {
lastItemId: 0,
lastDeliveryId: 0,
lastVoucherId: 0,
lastGiftcardId: 0,
lastAccess: ts,
lastChange: ts,
TotalDiscount: NewPrice(),
Vouchers: []*Voucher{},
Deliveries: []*CartDelivery{},
Giftcards: []*GiftcardItem{},
Id: CartId(id),
Items: []*CartItem{},
TotalPrice: NewPrice(),
@@ -337,6 +351,9 @@ func (c *CartGrain) UpdateTotals() {
for _, delivery := range c.Deliveries {
c.TotalPrice.Add(delivery.Price)
}
for _, giftcard := range c.Giftcards {
c.TotalPrice.Add(giftcard.Value)
}
for _, voucher := range c.Vouchers {
_, ok := voucher.AppliesTo(c)
voucher.Applied = false