Fix: Extract categories from __OO_STATE__ groups

The __OO_STATE__ parsing was only extracting images, not the group names
as categories. Now extracts category names from menu.groups and maps
items to their proper categories.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-02-13 10:06:43 -08:00
parent fb21b0c58d
commit 90ed78fa96

View file

@ -285,8 +285,9 @@
<!--- Debug: log all top-level keys in OO_STATE --->
<cfset ooStateKeys = structKeyList(ooState)>
<cfset arrayAppend(response.steps, "OO_STATE keys: " & left(ooStateKeys, 500))>
<!--- Build name -> image URL map from OO_STATE --->
<!--- Build name -> image URL map and name -> category map from OO_STATE --->
<cfset imageMap = structNew()>
<cfset itemCategoryMap = structNew()>
<cfloop collection="#ooState#" item="key">
<!--- Extract restaurant/business info --->
<cfif left(key, 11) EQ "Restaurant:">
@ -316,19 +317,36 @@
<cfset toastBusiness["brandColor"] = replace(restaurant.brandColor, "##", "")>
</cfif>
</cfif>
<!--- Extract menu items and images --->
<!--- Extract menu items, images, and CATEGORIES --->
<cfif left(key, 5) EQ "Menu:">
<cfset menu = ooState[key]>
<cfif structKeyExists(menu, "groups") AND isArray(menu.groups)>
<cfloop array="#menu.groups#" index="group">
<!--- Extract category name from group --->
<cfset groupName = "">
<cfif structKeyExists(group, "name") AND len(trim(group.name))>
<cfset groupName = trim(group.name)>
<!--- Add to categories if not already there --->
<cfif NOT structKeyExists(categorySet, groupName)>
<cfset categorySet[groupName] = true>
<cfset arrayAppend(toastCategories, { "name": groupName, "itemCount": 0 })>
</cfif>
</cfif>
<cfif structKeyExists(group, "items") AND isArray(group.items)>
<cfloop array="#group.items#" index="item">
<cfif structKeyExists(item, "name") AND structKeyExists(item, "imageUrls")>
<cfset imgUrls = item.imageUrls>
<cfif structKeyExists(imgUrls, "medium")>
<cfset imageMap[item.name] = imgUrls.medium>
<cfelseif structKeyExists(imgUrls, "large")>
<cfset imageMap[item.name] = imgUrls.large>
<cfif structKeyExists(item, "name")>
<!--- Map item name to category --->
<cfif len(groupName)>
<cfset itemCategoryMap[item.name] = groupName>
</cfif>
<!--- Extract image URLs --->
<cfif structKeyExists(item, "imageUrls")>
<cfset imgUrls = item.imageUrls>
<cfif structKeyExists(imgUrls, "medium")>
<cfset imageMap[item.name] = imgUrls.medium>
<cfelseif structKeyExists(imgUrls, "large")>
<cfset imageMap[item.name] = imgUrls.large>
</cfif>
</cfif>
</cfif>
</cfloop>
@ -337,8 +355,9 @@
</cfif>
</cfif>
</cfloop>
<!--- Apply images to items --->
<!--- Apply images and categories to items --->
<cfset imagesMatched = 0>
<cfset categoriesMatched = 0>
<cfloop from="1" to="#arrayLen(toastItems)#" index="i">
<cfif structKeyExists(imageMap, toastItems[i].name)>
<cfset toastItems[i]["imageUrl"] = imageMap[toastItems[i].name]>
@ -346,8 +365,13 @@
<cfset toastItems[i]["imageFilename"] = listLast(imageMap[toastItems[i].name], "/")>
<cfset imagesMatched++>
</cfif>
<!--- Apply category from __OO_STATE__ --->
<cfif structKeyExists(itemCategoryMap, toastItems[i].name)>
<cfset toastItems[i]["category"] = itemCategoryMap[toastItems[i].name]>
<cfset categoriesMatched++>
</cfif>
</cfloop>
<cfset arrayAppend(response.steps, "Matched " & imagesMatched & " images from __OO_STATE__")>
<cfset arrayAppend(response.steps, "Matched " & imagesMatched & " images, " & categoriesMatched & " categories from __OO_STATE__")>
<cfif structCount(toastBusiness) GT 0>
<cfset arrayAppend(response.steps, "Extracted business info: " & structKeyList(toastBusiness))>
</cfif>