Skip empty categories in menu API response
Only include category headers that actually have items assigned to them, preventing empty categories from showing up in the app. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
6b31b1abcf
commit
a5fa1c1041
1 changed files with 30 additions and 22 deletions
|
|
@ -300,12 +300,19 @@
|
|||
|
||||
<cfset rows = []>
|
||||
|
||||
<!--- For unified schema with Categories table, add category headers first --->
|
||||
<!--- Build set of category IDs that actually have items --->
|
||||
<cfset categoriesWithItems = {}>
|
||||
<cfloop query="q">
|
||||
<cfif q.ItemCategoryID GT 0>
|
||||
<cfset categoriesWithItems[q.ItemCategoryID] = true>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<!--- For unified schema with Categories table, add category headers (only if they have items) --->
|
||||
<cfif newSchemaActive AND isDefined("qCategories")>
|
||||
<cfloop query="qCategories">
|
||||
<cfif structKeyExists(categoriesWithItems, qCategories.CategoryID)>
|
||||
<!--- Add category as a virtual parent item --->
|
||||
<!--- Use CategoryID as ItemID, and set ItemCategoryID to same value --->
|
||||
<!--- Set ItemParentItemID to 0 to mark as root level --->
|
||||
<cfset arrayAppend(rows, {
|
||||
"ItemID": qCategories.CategoryID,
|
||||
"ItemCategoryID": qCategories.CategoryID,
|
||||
|
|
@ -324,6 +331,7 @@
|
|||
"ItemStationName": "",
|
||||
"ItemStationColor": ""
|
||||
})>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
|
|
|
|||
Reference in a new issue