Fix attachDefaultChildren to recurse through modifier groups
Default-checked items nested inside modifier groups were not being found because the function only looked one level deep. Now it recurses through all child items to find defaults at any depth. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
0451c604e6
commit
65f236268c
1 changed files with 29 additions and 18 deletions
|
|
@ -43,13 +43,18 @@
|
|||
<cfargument name="ParentLineItemID" type="numeric" required="true">
|
||||
<cfargument name="ParentItemID" type="numeric" required="true">
|
||||
|
||||
<!--- Find immediate children where checked by default --->
|
||||
<cfset var qKids = queryTimed(
|
||||
<!--- Store debug info in request scope for response --->
|
||||
<cfif NOT structKeyExists(request, "attachDebug")>
|
||||
<cfset request.attachDebug = []>
|
||||
</cfif>
|
||||
<cfset arrayAppend(request.attachDebug, "attachDefaultChildren: OrderID=#arguments.OrderID#, ParentLI=#arguments.ParentLineItemID#, ParentItemID=#arguments.ParentItemID#")>
|
||||
|
||||
<!--- Find ALL immediate children (to recurse into groups) --->
|
||||
<cfset var qAllKids = queryTimed(
|
||||
"
|
||||
SELECT ID, Price
|
||||
SELECT ID, Price, IsCheckedByDefault
|
||||
FROM Items
|
||||
WHERE ParentItemID = ?
|
||||
AND IsCheckedByDefault = 1
|
||||
AND IsActive = 1
|
||||
ORDER BY SortOrder, ID
|
||||
",
|
||||
|
|
@ -57,14 +62,13 @@
|
|||
{ datasource = "payfrit" }
|
||||
)>
|
||||
|
||||
<!--- Also find default children from templates linked to this item --->
|
||||
<!--- Also find children from templates linked to this item --->
|
||||
<cfset var qTemplateKids = queryTimed(
|
||||
"
|
||||
SELECT i.ID, i.Price
|
||||
SELECT i.ID, i.Price, i.IsCheckedByDefault
|
||||
FROM lt_ItemID_TemplateItemID tl
|
||||
INNER JOIN Items i ON i.ParentItemID = tl.TemplateItemID
|
||||
WHERE tl.ItemID = ?
|
||||
AND i.IsCheckedByDefault = 1
|
||||
AND i.IsActive = 1
|
||||
ORDER BY i.SortOrder, i.ID
|
||||
",
|
||||
|
|
@ -72,23 +76,30 @@
|
|||
{ datasource = "payfrit" }
|
||||
)>
|
||||
|
||||
<!--- Store debug info in request scope for response --->
|
||||
<cfif NOT structKeyExists(request, "attachDebug")>
|
||||
<cfset request.attachDebug = []>
|
||||
</cfif>
|
||||
<cfset arrayAppend(request.attachDebug, "attachDefaultChildren: OrderID=#arguments.OrderID#, ParentLI=#arguments.ParentLineItemID#, ParentItemID=#arguments.ParentItemID#")>
|
||||
<cfset arrayAppend(request.attachDebug, " qKids=#qKids.recordCount# rows, qTemplateKids=#qTemplateKids.recordCount# rows")>
|
||||
<cfset arrayAppend(request.attachDebug, " qAllKids=#qAllKids.recordCount# rows, qTemplateKids=#qTemplateKids.recordCount# rows")>
|
||||
|
||||
<!--- Process direct children --->
|
||||
<cfloop query="qKids">
|
||||
<cfset arrayAppend(request.attachDebug, " -> direct child: ItemID=#qKids.ID#")>
|
||||
<cfset processDefaultChild(arguments.OrderID, arguments.ParentLineItemID, qKids.ID, qKids.Price)>
|
||||
<cfloop query="qAllKids">
|
||||
<cfif val(qAllKids.IsCheckedByDefault) EQ 1>
|
||||
<!--- This child is default-checked, add it to the order --->
|
||||
<cfset arrayAppend(request.attachDebug, " -> add default child: ItemID=#qAllKids.ID#")>
|
||||
<cfset processDefaultChild(arguments.OrderID, arguments.ParentLineItemID, qAllKids.ID, qAllKids.Price)>
|
||||
<cfelse>
|
||||
<!--- This child is not default-checked, but recurse into it to find nested defaults --->
|
||||
<cfset arrayAppend(request.attachDebug, " -> recurse into group: ItemID=#qAllKids.ID#")>
|
||||
<cfset attachDefaultChildren(arguments.OrderID, arguments.ParentLineItemID, qAllKids.ID)>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<!--- Process template children --->
|
||||
<cfloop query="qTemplateKids">
|
||||
<cfset arrayAppend(request.attachDebug, " -> template child: ItemID=#qTemplateKids.ID#")>
|
||||
<cfif val(qTemplateKids.IsCheckedByDefault) EQ 1>
|
||||
<cfset arrayAppend(request.attachDebug, " -> add template child: ItemID=#qTemplateKids.ID#")>
|
||||
<cfset processDefaultChild(arguments.OrderID, arguments.ParentLineItemID, qTemplateKids.ID, qTemplateKids.Price)>
|
||||
<cfelse>
|
||||
<cfset arrayAppend(request.attachDebug, " -> recurse into template group: ItemID=#qTemplateKids.ID#")>
|
||||
<cfset attachDefaultChildren(arguments.OrderID, arguments.ParentLineItemID, qTemplateKids.ID)>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cffunction>
|
||||
|
||||
|
|
|
|||
Reference in a new issue