Add menu list and MenuID filter to items.cfm API
Returns active menus in response so mobile apps can show menu selector chips. Accepts optional MenuID param to filter items to a specific menu. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9091461079
commit
3b48c3331d
1 changed files with 26 additions and 3 deletions
|
|
@ -38,6 +38,12 @@
|
|||
<cfset OrderTypeID = val(data.OrderTypeID)>
|
||||
</cfif>
|
||||
|
||||
<!--- Optional MenuID for menu filtering (0 = all active menus) --->
|
||||
<cfset requestedMenuID = 0>
|
||||
<cfif structKeyExists(data, "MenuID")>
|
||||
<cfset requestedMenuID = val(data.MenuID)>
|
||||
</cfif>
|
||||
|
||||
<cfif BusinessID LTE 0>
|
||||
<cfset apiAbort({ "OK": false, "ERROR": "missing_businessid", "MESSAGE": "BusinessID is required.", "DETAIL": "" })>
|
||||
</cfif>
|
||||
|
|
@ -46,6 +52,7 @@
|
|||
<cfset currentTime = timeFormat(now(), "HH:mm:ss")>
|
||||
<cfset currentDayID = dayOfWeek(now())>
|
||||
|
||||
<cfset menuList = []>
|
||||
<cftry>
|
||||
<!--- Check if new schema is active (ItemBusinessID column exists and has data) --->
|
||||
<cfset newSchemaActive = false>
|
||||
|
|
@ -82,10 +89,11 @@
|
|||
<!--- Use Categories table with ItemCategoryID --->
|
||||
<!--- First, find which menus are currently active based on day/time --->
|
||||
<cfset activeMenuIds = "">
|
||||
<cfset menuList = []>
|
||||
<cftry>
|
||||
<cfset qActiveMenus = queryExecute(
|
||||
"
|
||||
SELECT MenuID FROM Menus
|
||||
SELECT MenuID, MenuName FROM Menus
|
||||
WHERE MenuBusinessID = :bizId
|
||||
AND MenuIsActive = 1
|
||||
AND (MenuDaysActive & :dayBit) > 0
|
||||
|
|
@ -93,6 +101,7 @@
|
|||
(MenuStartTime IS NULL OR MenuEndTime IS NULL)
|
||||
OR (TIME(:currentTime) >= MenuStartTime AND TIME(:currentTime) <= MenuEndTime)
|
||||
)
|
||||
ORDER BY MenuSortOrder, MenuName
|
||||
",
|
||||
{
|
||||
bizId: { value = BusinessID, cfsqltype = "cf_sql_integer" },
|
||||
|
|
@ -101,7 +110,19 @@
|
|||
},
|
||||
{ datasource = "payfrit" }
|
||||
)>
|
||||
<cfset activeMenuIds = valueList(qActiveMenus.MenuID)>
|
||||
<cfif requestedMenuID GT 0>
|
||||
<!--- User selected a specific menu --->
|
||||
<cfset activeMenuIds = requestedMenuID>
|
||||
<cfelse>
|
||||
<cfset activeMenuIds = valueList(qActiveMenus.MenuID)>
|
||||
</cfif>
|
||||
<!--- Build menu list for the response --->
|
||||
<cfloop query="qActiveMenus">
|
||||
<cfset arrayAppend(menuList, {
|
||||
"MenuID": qActiveMenus.MenuID,
|
||||
"MenuName": qActiveMenus.MenuName
|
||||
})>
|
||||
</cfloop>
|
||||
<cfcatch>
|
||||
<!--- Menus table might not exist yet --->
|
||||
</cfcatch>
|
||||
|
|
@ -510,7 +531,9 @@
|
|||
"Items": rows,
|
||||
"COUNT": arrayLen(rows),
|
||||
"SCHEMA": newSchemaActive ? "unified" : "legacy",
|
||||
"BRANDCOLOR": brandColor
|
||||
"BRANDCOLOR": brandColor,
|
||||
"Menus": menuList,
|
||||
"SelectedMenuID": requestedMenuID
|
||||
})>
|
||||
|
||||
<cfcatch>
|
||||
|
|
|
|||
Reference in a new issue