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 = []>
|
<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")>
|
<cfif newSchemaActive AND isDefined("qCategories")>
|
||||||
<cfloop query="qCategories">
|
<cfloop query="qCategories">
|
||||||
<!--- Add category as a virtual parent item --->
|
<cfif structKeyExists(categoriesWithItems, qCategories.CategoryID)>
|
||||||
<!--- Use CategoryID as ItemID, and set ItemCategoryID to same value --->
|
<!--- Add category as a virtual parent item --->
|
||||||
<!--- Set ItemParentItemID to 0 to mark as root level --->
|
<cfset arrayAppend(rows, {
|
||||||
<cfset arrayAppend(rows, {
|
"ItemID": qCategories.CategoryID,
|
||||||
"ItemID": qCategories.CategoryID,
|
"ItemCategoryID": qCategories.CategoryID,
|
||||||
"ItemCategoryID": qCategories.CategoryID,
|
"ItemCategoryName": qCategories.CategoryName,
|
||||||
"ItemCategoryName": qCategories.CategoryName,
|
"ItemName": qCategories.CategoryName,
|
||||||
"ItemName": qCategories.CategoryName,
|
"ItemDescription": "",
|
||||||
"ItemDescription": "",
|
"ItemParentItemID": 0,
|
||||||
"ItemParentItemID": 0,
|
"ItemPrice": 0,
|
||||||
"ItemPrice": 0,
|
"ItemIsActive": 1,
|
||||||
"ItemIsActive": 1,
|
"ItemIsCheckedByDefault": 0,
|
||||||
"ItemIsCheckedByDefault": 0,
|
"ItemRequiresChildSelection": 0,
|
||||||
"ItemRequiresChildSelection": 0,
|
"ItemMaxNumSelectionReq": 0,
|
||||||
"ItemMaxNumSelectionReq": 0,
|
"ItemIsCollapsible": 0,
|
||||||
"ItemIsCollapsible": 0,
|
"ItemSortOrder": qCategories.CategorySortOrder,
|
||||||
"ItemSortOrder": qCategories.CategorySortOrder,
|
"ItemStationID": "",
|
||||||
"ItemStationID": "",
|
"ItemStationName": "",
|
||||||
"ItemStationName": "",
|
"ItemStationColor": ""
|
||||||
"ItemStationColor": ""
|
})>
|
||||||
})>
|
</cfif>
|
||||||
</cfloop>
|
</cfloop>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue