parent item mutations
Build and Publish / BuildAndDeployAmd64 (push) Failing after 5s
Build and Publish / BuildAndDeployArm64 (push) Failing after 7s

This commit is contained in:
2026-07-08 11:39:42 +02:00
parent e20793a6b3
commit 9f1eca07e9
14 changed files with 784 additions and 103 deletions
+15
View File
@@ -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
}