handle limited quantity
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 36s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m43s

This commit is contained in:
2025-11-26 21:35:40 +01:00
parent a17d5fc570
commit afa79e7b56
3 changed files with 32 additions and 8 deletions

View File

@@ -38,16 +38,24 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
if !sameStore {
continue
}
existing.Quantity += int(m.Quantity)
if m.ReservationEndTime != nil {
t := m.ReservationEndTime.AsTime()
if existing.ReservationEndTime == nil || existing.ReservationEndTime.Before(m.ReservationEndTime.AsTime()) {
existing.ReservationEndTime = &t
existing.Quantity = int(m.Quantity)
} else {
existing.ReservationEndTime = &t
}
} else {
existing.Quantity += int(m.Quantity)
}
existing.Stock = uint16(m.Stock)
// If existing had nil store but new has one, adopt it.
if existing.StoreId == nil && m.StoreId != nil {
existing.StoreId = m.StoreId
}
if m.ReservationEndTime != nil {
t := m.ReservationEndTime.AsTime()
existing.ReservationEndTime = &t
}
return nil
}