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,30 +300,38 @@
|
|||
|
||||
<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">
|
||||
<!--- 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,
|
||||
"ItemCategoryName": qCategories.CategoryName,
|
||||
"ItemName": qCategories.CategoryName,
|
||||
"ItemDescription": "",
|
||||
"ItemParentItemID": 0,
|
||||
"ItemPrice": 0,
|
||||
"ItemIsActive": 1,
|
||||
"ItemIsCheckedByDefault": 0,
|
||||
"ItemRequiresChildSelection": 0,
|
||||
"ItemMaxNumSelectionReq": 0,
|
||||
"ItemIsCollapsible": 0,
|
||||
"ItemSortOrder": qCategories.CategorySortOrder,
|
||||
"ItemStationID": "",
|
||||
"ItemStationName": "",
|
||||
"ItemStationColor": ""
|
||||
})>
|
||||
<cfif structKeyExists(categoriesWithItems, qCategories.CategoryID)>
|
||||
<!--- Add category as a virtual parent item --->
|
||||
<cfset arrayAppend(rows, {
|
||||
"ItemID": qCategories.CategoryID,
|
||||
"ItemCategoryID": qCategories.CategoryID,
|
||||
"ItemCategoryName": qCategories.CategoryName,
|
||||
"ItemName": qCategories.CategoryName,
|
||||
"ItemDescription": "",
|
||||
"ItemParentItemID": 0,
|
||||
"ItemPrice": 0,
|
||||
"ItemIsActive": 1,
|
||||
"ItemIsCheckedByDefault": 0,
|
||||
"ItemRequiresChildSelection": 0,
|
||||
"ItemMaxNumSelectionReq": 0,
|
||||
"ItemIsCollapsible": 0,
|
||||
"ItemSortOrder": qCategories.CategorySortOrder,
|
||||
"ItemStationID": "",
|
||||
"ItemStationName": "",
|
||||
"ItemStationColor": ""
|
||||
})>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
</cfif>
|
||||
|
||||
|
|
|
|||
Reference in a new issue