From a4fb7e7503866c65ffe57172bec81c8d23f3c9af Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Thu, 15 Jan 2026 15:17:08 -0800 Subject: [PATCH] Show all templates in menu builder regardless of links - Changed template query to find ALL templates for business (ItemCategoryID=0, ItemParentItemID=0) - Previously only showed templates that were in ItemTemplateLinks - Now shows all templates so they can be viewed and manually assigned to items - Template children query also updated to include children of all templates Co-Authored-By: Claude Sonnet 4.5 --- api/menu/getForBuilder.cfm | 78 +++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/api/menu/getForBuilder.cfm b/api/menu/getForBuilder.cfm index 67ff349..9f7c43d 100644 --- a/api/menu/getForBuilder.cfm +++ b/api/menu/getForBuilder.cfm @@ -178,7 +178,8 @@ try { ORDER BY tl.ItemID, tl.SortOrder ", {}, { datasource: "payfrit" }); - // Get all templates for this business (items that appear in ItemTemplateLinks) + // Get all templates for this business + // Templates are Items with ItemCategoryID=0 and ItemParentItemID=0 if (newSchemaActive) { qTemplates = queryExecute(" SELECT DISTINCT @@ -190,9 +191,9 @@ try { t.ItemRequiresChildSelection as RequiresSelection, t.ItemMaxNumSelectionReq as MaxSelections FROM Items t - INNER JOIN ItemTemplateLinks tl ON tl.TemplateItemID = t.ItemID - INNER JOIN Items i ON i.ItemID = tl.ItemID - WHERE i.ItemBusinessID = :businessID + WHERE t.ItemBusinessID = :businessID + AND t.ItemCategoryID = 0 + AND t.ItemParentItemID = 0 AND t.ItemIsActive = 1 ORDER BY t.ItemSortOrder, t.ItemName ", { businessID: businessID }, { datasource: "payfrit" }); @@ -217,29 +218,52 @@ try { } // Get all children of templates (options within modifier groups) - // This now includes ALL descendants recursively via a recursive approach - // Filter by business and use DISTINCT to avoid duplicates from multiple template links - qTemplateChildren = queryExecute(" - SELECT DISTINCT - c.ItemID, - c.ItemParentItemID as ParentItemID, - c.ItemName, - c.ItemPrice, - c.ItemIsCheckedByDefault as IsDefault, - c.ItemSortOrder, - c.ItemRequiresChildSelection as RequiresSelection, - c.ItemMaxNumSelectionReq as MaxSelections - FROM Items c - WHERE c.ItemParentItemID IN ( - SELECT DISTINCT t.ItemID - FROM Items t - INNER JOIN ItemTemplateLinks tl ON tl.TemplateItemID = t.ItemID - INNER JOIN Items i ON i.ItemID = tl.ItemID - WHERE i.ItemBusinessID = :businessID - ) - AND c.ItemIsActive = 1 - ORDER BY c.ItemSortOrder, c.ItemName - ", { businessID: businessID }, { datasource: "payfrit" }); + // Get children of ALL templates for this business (not just linked ones) + if (newSchemaActive) { + qTemplateChildren = queryExecute(" + SELECT DISTINCT + c.ItemID, + c.ItemParentItemID as ParentItemID, + c.ItemName, + c.ItemPrice, + c.ItemIsCheckedByDefault as IsDefault, + c.ItemSortOrder, + c.ItemRequiresChildSelection as RequiresSelection, + c.ItemMaxNumSelectionReq as MaxSelections + FROM Items c + WHERE c.ItemParentItemID IN ( + SELECT t.ItemID + FROM Items t + WHERE t.ItemBusinessID = :businessID + AND t.ItemCategoryID = 0 + AND t.ItemParentItemID = 0 + ) + AND c.ItemIsActive = 1 + ORDER BY c.ItemSortOrder, c.ItemName + ", { businessID: businessID }, { datasource: "payfrit" }); + } else { + qTemplateChildren = queryExecute(" + SELECT DISTINCT + c.ItemID, + c.ItemParentItemID as ParentItemID, + c.ItemName, + c.ItemPrice, + c.ItemIsCheckedByDefault as IsDefault, + c.ItemSortOrder, + c.ItemRequiresChildSelection as RequiresSelection, + c.ItemMaxNumSelectionReq as MaxSelections + FROM Items c + WHERE c.ItemParentItemID IN ( + SELECT DISTINCT t.ItemID + FROM Items t + INNER JOIN ItemTemplateLinks tl ON tl.TemplateItemID = t.ItemID + INNER JOIN Items i ON i.ItemID = tl.ItemID + WHERE i.ItemBusinessID = :businessID + ) + AND c.ItemIsActive = 1 + ORDER BY c.ItemSortOrder, c.ItemName + ", { businessID: businessID }, { datasource: "payfrit" }); + } // Build lookup of children by parent ID (flat list for now) childrenByParent = {};