mutation fixes
This commit is contained in:
@@ -87,15 +87,25 @@ func (c *CartMutationContext) AddItem(g *CartGrain, m *cart_messages.AddItem) er
|
||||
return fmt.Errorf("AddItem: invalid quantity %d", m.Quantity)
|
||||
}
|
||||
|
||||
// Merge with any existing item having the same item id and matching StoreId
|
||||
// (including both nil). Identity is the id; SKU is reference-only.
|
||||
// Merge with any existing item having the same item id, matching
|
||||
// StoreId, and matching ParentId (all three including both nil).
|
||||
// Identity is ItemId; SKU is reference-only.
|
||||
//
|
||||
// ParentId MUST match: a standalone root line (ParentId == nil) and
|
||||
// a child line (ParentId == &someParentLine) that happen to share an
|
||||
// ItemId are different roles in the cart, even though the catalog
|
||||
// item is the same. Merging them would silently convert an accessory
|
||||
// into a +N on the root (or vice versa), corrupting the parent-child
|
||||
// link. Both checks are delegated to equalOptional so the nullable-
|
||||
// equality idiom stays in one place (cart-mutation-helper.go).
|
||||
for _, existing := range g.Items {
|
||||
if existing.ItemId != m.ItemId {
|
||||
continue
|
||||
}
|
||||
sameStore := (existing.StoreId == nil && m.StoreId == nil) ||
|
||||
(existing.StoreId != nil && m.StoreId != nil && *existing.StoreId == *m.StoreId)
|
||||
if !sameStore {
|
||||
if !equalOptional(existing.StoreId, m.StoreId) {
|
||||
continue
|
||||
}
|
||||
if !equalOptional(existing.ParentId, m.ParentId) {
|
||||
continue
|
||||
}
|
||||
if g.Type == cart_messages.CartType_REGULAR && c.UseReservations(existing) {
|
||||
|
||||
Reference in New Issue
Block a user