update if same, else add new
This commit is contained in:
@@ -30,9 +30,13 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
|
||||
|
||||
// Fast path: merge with existing item having same SKU
|
||||
if existing, found := g.FindItemWithSku(m.Sku); found {
|
||||
if existing.StoreId == m.StoreId {
|
||||
existing.Quantity += int(m.Quantity)
|
||||
existing.Stock = StockStatus(m.Stock)
|
||||
existing.StoreId = m.StoreId
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
g.mu.Lock()
|
||||
defer g.mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user