From f6428a14ff70dbcd3a373dad4451807c376aacf5 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Tue, 13 Jan 2026 22:51:59 -0800 Subject: [PATCH] Fix modifier nesting - don't add intermediate groups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user customizes an item, add selections directly under the root item instead of creating an intermediate group node. This matches how attachDefaultChildren works on the server and prevents duplicate modifiers showing in KDS. Before: Double Double → Customize Lettuce → Light, Extra After: Double Double → Light, Extra Co-Authored-By: Claude Opus 4.5 --- lib/screens/menu_browse_screen.dart | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/screens/menu_browse_screen.dart b/lib/screens/menu_browse_screen.dart index a4397b0..45182ed 100644 --- a/lib/screens/menu_browse_screen.dart +++ b/lib/screens/menu_browse_screen.dart @@ -1165,6 +1165,7 @@ class _MenuBrowseScreenState extends State { final realChildItemId = _decodeVirtualId(child.itemId); if (isSelected) { + // This item is directly selected - add it final cart = await Api.setLineItem( orderId: orderId, parentOrderLineItemId: parentOrderLineItemId, @@ -1186,21 +1187,13 @@ class _MenuBrowseScreenState extends State { ); } } else if (hasSelectedDescendants) { - final cart = await Api.setLineItem( - orderId: orderId, - parentOrderLineItemId: parentOrderLineItemId, - itemId: child.itemId, - isSelected: true, - ); - - final childLineItem = cart.lineItems.lastWhere( - (li) => li.itemId == realChildItemId && li.parentOrderLineItemId == parentOrderLineItemId && !li.isDeleted, - orElse: () => throw StateError('Failed to add item'), - ); - + // This item is NOT selected, but has selected descendants + // DON'T add this intermediate group - just recurse to add the actual selections + // The selections will be added directly under the current parent + // This matches how attachDefaultChildren works on the server await _addModifiersRecursively( orderId, - childLineItem.orderLineItemId, + parentOrderLineItemId, // Keep the same parent - don't create intermediate node child.itemId, selectedItemIds, );