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:
parent
a0d86d6e87
commit
e403e49487
1 changed files with 59 additions and 8 deletions
|
|
@ -953,14 +953,45 @@
|
||||||
<cfset itemId = 1>
|
<cfset itemId = 1>
|
||||||
<cfset menuNames = arrayNew(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">
|
<cfloop collection="#ooState#" item="ooKey">
|
||||||
<!--- Extract restaurant info --->
|
<cfif left(ooKey, 11) EQ "Restaurant:" AND NOT structKeyExists(toastBusiness, "name")>
|
||||||
<cfif left(ooKey, 11) EQ "Restaurant:">
|
|
||||||
<cfset restaurant = ooState[ooKey]>
|
<cfset restaurant = ooState[ooKey]>
|
||||||
<cfif structKeyExists(restaurant, "name")>
|
<cfif structKeyExists(restaurant, "name")>
|
||||||
<cfset toastBusiness["name"] = restaurant.name>
|
<cfset toastBusiness["name"] = restaurant.name>
|
||||||
</cfif>
|
</cfif>
|
||||||
<cfif structKeyExists(restaurant, "location")>
|
<cfif structKeyExists(restaurant, "location") AND isStruct(restaurant.location)>
|
||||||
<cfset loc = restaurant.location>
|
<cfset loc = restaurant.location>
|
||||||
<cfif structKeyExists(loc, "address1")>
|
<cfif structKeyExists(loc, "address1")>
|
||||||
<cfset toastBusiness["address"] = loc.address1>
|
<cfset toastBusiness["address"] = loc.address1>
|
||||||
|
|
@ -1008,9 +1039,11 @@
|
||||||
<cfset itemStruct["description"] = trim(toString(item.description))>
|
<cfset itemStruct["description"] = trim(toString(item.description))>
|
||||||
</cfif>
|
</cfif>
|
||||||
|
|
||||||
<!--- Extract price --->
|
<!--- Extract price: Toast uses "prices" array [4.50] or scalar "price" --->
|
||||||
<cfset itemStruct["price"] = 0>
|
<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)>
|
<cfset itemStruct["price"] = val(item.price)>
|
||||||
<cfelseif structKeyExists(item, "unitPrice") AND isNumeric(item.unitPrice)>
|
<cfelseif structKeyExists(item, "unitPrice") AND isNumeric(item.unitPrice)>
|
||||||
<cfset itemStruct["price"] = val(item.unitPrice)>
|
<cfset itemStruct["price"] = val(item.unitPrice)>
|
||||||
|
|
@ -1025,7 +1058,7 @@
|
||||||
|
|
||||||
<!--- Extract image URL --->
|
<!--- Extract image URL --->
|
||||||
<cfset itemStruct["imageUrl"] = "">
|
<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")>
|
<cfif structKeyExists(item.imageUrls, "medium")>
|
||||||
<cfset itemStruct["imageUrl"] = item.imageUrls.medium>
|
<cfset itemStruct["imageUrl"] = item.imageUrls.medium>
|
||||||
<cfelseif structKeyExists(item.imageUrls, "large")>
|
<cfelseif structKeyExists(item.imageUrls, "large")>
|
||||||
|
|
@ -1073,7 +1106,9 @@
|
||||||
<cfset itemStruct["description"] = trim(toString(subItem.description))>
|
<cfset itemStruct["description"] = trim(toString(subItem.description))>
|
||||||
</cfif>
|
</cfif>
|
||||||
<cfset itemStruct["price"] = 0>
|
<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)>
|
<cfset itemStruct["price"] = val(subItem.price)>
|
||||||
<cfelseif structKeyExists(subItem, "unitPrice") AND isNumeric(subItem.unitPrice)>
|
<cfelseif structKeyExists(subItem, "unitPrice") AND isNumeric(subItem.unitPrice)>
|
||||||
<cfset itemStruct["price"] = val(subItem.unitPrice)>
|
<cfset itemStruct["price"] = val(subItem.unitPrice)>
|
||||||
|
|
@ -1086,7 +1121,7 @@
|
||||||
</cfif>
|
</cfif>
|
||||||
</cfif>
|
</cfif>
|
||||||
<cfset itemStruct["imageUrl"] = "">
|
<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")>
|
<cfif structKeyExists(subItem.imageUrls, "medium")>
|
||||||
<cfset itemStruct["imageUrl"] = subItem.imageUrls.medium>
|
<cfset itemStruct["imageUrl"] = subItem.imageUrls.medium>
|
||||||
<cfelseif structKeyExists(subItem.imageUrls, "large")>
|
<cfelseif structKeyExists(subItem.imageUrls, "large")>
|
||||||
|
|
@ -1110,6 +1145,22 @@
|
||||||
</cfif>
|
</cfif>
|
||||||
</cfloop>
|
</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 --->
|
<!--- Update category item counts --->
|
||||||
<cfloop from="1" to="#arrayLen(toastCategories)#" index="ci">
|
<cfloop from="1" to="#arrayLen(toastCategories)#" index="ci">
|
||||||
<cfset catName = toastCategories[ci].name>
|
<cfset catName = toastCategories[ci].name>
|
||||||
|
|
|
||||||
Reference in a new issue