parent item mutations
This commit is contained in:
@@ -108,6 +108,7 @@ func (c *CartMutationContext) AddItem(g *CartGrain, m *cart_messages.AddItem) er
|
||||
}
|
||||
existing.ReservationEndTime = endTime
|
||||
}
|
||||
oldQty := existing.Quantity
|
||||
existing.Quantity += uint16(m.Quantity)
|
||||
existing.Stock = uint16(m.Stock)
|
||||
existing.InventoryTracked = m.InventoryTracked
|
||||
@@ -124,6 +125,20 @@ func (c *CartMutationContext) AddItem(g *CartGrain, m *cart_messages.AddItem) er
|
||||
if len(m.CustomFields) > 0 {
|
||||
existing.CustomFields = m.CustomFields
|
||||
}
|
||||
// Re-add grew the parent's qty — rescale direct child quantities
|
||||
// proportionally so a "+1 drill" keeps its accessories consistent.
|
||||
// Skip when the merged line IS itself a child (ParentId != nil):
|
||||
// cascading up the tree isn't a thing — the parent would not know
|
||||
// a child grew without re-running the promotion engine.
|
||||
if existing.ParentId == nil {
|
||||
c.CascadeChildQuantities(ctx, g, existing.Id, oldQty, existing.Quantity)
|
||||
}
|
||||
// Recompute totals so TotalPrice/TotalDiscount/Discount annotations
|
||||
// reflect the merged parent + cascaded children. The non-merge
|
||||
// (new-line) path below also calls UpdateTotals; the merge path
|
||||
// would otherwise drift after a "+1" re-add, especially now that
|
||||
// cascade may have rewritten N child quantities.
|
||||
g.UpdateTotals()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user