Fix Toast OO_STATE: restaurant from ROOT_QUERY, prices from prices[]

- Restaurant info is in ROOT_QUERY.restaurantV2(...) keys, not
  Restaurant:* top-level keys (Apollo cache format)
- Prices are in item.prices array [4.50], not item.price scalar
- Added null checks for imageUrls (can be null, not missing)
- Fallback to title tag for business name

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John Mizerek 2026-03-01 11:11:44 -08:00
parent a0d86d6e87
commit e403e49487

View file

@ -953,14 +953,45 @@
<cfset itemId = 1>
<cfset menuNames = arrayNew(1)>
<!--- Extract restaurant info from ROOT_QUERY (Apollo cache format) --->
<cfif structKeyExists(ooState, "ROOT_QUERY")>
<cfset rootQuery = ooState["ROOT_QUERY"]>
<cfloop collection="#rootQuery#" item="rqKey">
<cfif (findNoCase("restaurantV2By", rqKey) OR findNoCase("restaurantV2(", rqKey)) AND isStruct(rootQuery[rqKey])>
<cfset restaurant = rootQuery[rqKey]>
<cfif structKeyExists(restaurant, "name") AND NOT structKeyExists(toastBusiness, "name")>
<cfset toastBusiness["name"] = restaurant.name>
</cfif>
<cfif structKeyExists(restaurant, "description") AND NOT isNull(restaurant.description) AND len(trim(toString(restaurant.description)))>
<cfset toastBusiness["description"] = trim(toString(restaurant.description))>
</cfif>
<cfif structKeyExists(restaurant, "location") AND isStruct(restaurant.location)>
<cfset loc = restaurant.location>
<cfif structKeyExists(loc, "address1")>
<cfset toastBusiness["address"] = loc.address1>
<cfif structKeyExists(loc, "city") AND NOT isNull(loc.city)><cfset toastBusiness["address"] = toastBusiness.address & ", " & loc.city></cfif>
<cfif structKeyExists(loc, "state") AND NOT isNull(loc.state)><cfset toastBusiness["address"] = toastBusiness.address & ", " & loc.state></cfif>
<cfif structKeyExists(loc, "zip") AND NOT isNull(loc.zip)><cfset toastBusiness["address"] = toastBusiness.address & " " & loc.zip></cfif>
</cfif>
<cfif structKeyExists(loc, "phone") AND NOT isNull(loc.phone)>
<cfset toastBusiness["phone"] = loc.phone>
</cfif>
</cfif>
<cfif structKeyExists(restaurant, "brandColor") AND NOT isNull(restaurant.brandColor)>
<cfset toastBusiness["brandColor"] = replace(restaurant.brandColor, "##", "")>
</cfif>
</cfif>
</cfloop>
</cfif>
<!--- Also check for Restaurant: keys (older Toast format) --->
<cfloop collection="#ooState#" item="ooKey">
<!--- Extract restaurant info --->
<cfif left(ooKey, 11) EQ "Restaurant:">
<cfif left(ooKey, 11) EQ "Restaurant:" AND NOT structKeyExists(toastBusiness, "name")>
<cfset restaurant = ooState[ooKey]>
<cfif structKeyExists(restaurant, "name")>
<cfset toastBusiness["name"] = restaurant.name>
</cfif>
<cfif structKeyExists(restaurant, "location")>
<cfif structKeyExists(restaurant, "location") AND isStruct(restaurant.location)>
<cfset loc = restaurant.location>
<cfif structKeyExists(loc, "address1")>
<cfset toastBusiness["address"] = loc.address1>
@ -1008,9 +1039,11 @@
<cfset itemStruct["description"] = trim(toString(item.description))>
</cfif>
<!--- Extract price --->
<!--- Extract price: Toast uses "prices" array [4.50] or scalar "price" --->
<cfset itemStruct["price"] = 0>
<cfif structKeyExists(item, "price") AND isNumeric(item.price)>
<cfif structKeyExists(item, "prices") AND isArray(item.prices) AND arrayLen(item.prices) GT 0 AND isNumeric(item.prices[1])>
<cfset itemStruct["price"] = val(item.prices[1])>
<cfelseif structKeyExists(item, "price") AND isNumeric(item.price)>
<cfset itemStruct["price"] = val(item.price)>
<cfelseif structKeyExists(item, "unitPrice") AND isNumeric(item.unitPrice)>
<cfset itemStruct["price"] = val(item.unitPrice)>
@ -1025,7 +1058,7 @@
<!--- Extract image URL --->
<cfset itemStruct["imageUrl"] = "">
<cfif structKeyExists(item, "imageUrls") AND isStruct(item.imageUrls)>
<cfif structKeyExists(item, "imageUrls") AND NOT isNull(item.imageUrls) AND isStruct(item.imageUrls)>
<cfif structKeyExists(item.imageUrls, "medium")>
<cfset itemStruct["imageUrl"] = item.imageUrls.medium>
<cfelseif structKeyExists(item.imageUrls, "large")>
@ -1073,7 +1106,9 @@
<cfset itemStruct["description"] = trim(toString(subItem.description))>
</cfif>
<cfset itemStruct["price"] = 0>
<cfif structKeyExists(subItem, "price") AND isNumeric(subItem.price)>
<cfif structKeyExists(subItem, "prices") AND isArray(subItem.prices) AND arrayLen(subItem.prices) GT 0 AND isNumeric(subItem.prices[1])>
<cfset itemStruct["price"] = val(subItem.prices[1])>
<cfelseif structKeyExists(subItem, "price") AND isNumeric(subItem.price)>
<cfset itemStruct["price"] = val(subItem.price)>
<cfelseif structKeyExists(subItem, "unitPrice") AND isNumeric(subItem.unitPrice)>
<cfset itemStruct["price"] = val(subItem.unitPrice)>
@ -1086,7 +1121,7 @@
</cfif>
</cfif>
<cfset itemStruct["imageUrl"] = "">
<cfif structKeyExists(subItem, "imageUrls") AND isStruct(subItem.imageUrls)>
<cfif structKeyExists(subItem, "imageUrls") AND NOT isNull(subItem.imageUrls) AND isStruct(subItem.imageUrls)>
<cfif structKeyExists(subItem.imageUrls, "medium")>
<cfset itemStruct["imageUrl"] = subItem.imageUrls.medium>
<cfelseif structKeyExists(subItem.imageUrls, "large")>
@ -1110,6 +1145,22 @@
</cfif>
</cfloop>
<!--- Fallback: get business name from title tag if not found in OO_STATE --->
<cfif NOT structKeyExists(toastBusiness, "name") OR NOT len(toastBusiness.name)>
<cfset titleMatch = reMatchNoCase('<title[^>]*>([^<]+)</title>', pageHtml)>
<cfif arrayLen(titleMatch)>
<cfset titleText = reReplaceNoCase(titleMatch[1], '.*<title[^>]*>([^<]+)</title>.*', '\1')>
<cfset titleText = trim(titleText)>
<cfif findNoCase("|", titleText)>
<cfset titleText = trim(listFirst(titleText, "|"))>
</cfif>
<cfset titleText = reReplaceNoCase(titleText, "\s*-\s*(Menu|Order|Online).*$", "")>
<cfif len(titleText)>
<cfset toastBusiness["name"] = titleText>
</cfif>
</cfif>
</cfif>
<!--- Update category item counts --->
<cfloop from="1" to="#arrayLen(toastCategories)#" index="ci">
<cfset catName = toastCategories[ci].name>