From 552c404cf6b2c83320153d624b03c8686b1171f3 Mon Sep 17 00:00:00 2001 From: John Mizerek Date: Sat, 14 Mar 2026 16:45:34 -0700 Subject: [PATCH] Server-side address parsing: split combined address into components Claude returns address as one string with country suffix. Now strips "United States/USA", extracts ZIP, state, splits address line and city server-side before sending to wizard. Co-Authored-By: Claude Opus 4.6 --- api/setup/analyzeMenuUrl.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/api/setup/analyzeMenuUrl.php b/api/setup/analyzeMenuUrl.php index 57dd60c..ede81f4 100644 --- a/api/setup/analyzeMenuUrl.php +++ b/api/setup/analyzeMenuUrl.php @@ -1768,6 +1768,33 @@ try { if (!isset($menuData['modifiers'])) $menuData['modifiers'] = []; if (!isset($menuData['items'])) $menuData['items'] = []; + // Server-side address parsing: split combined address into components + $biz = &$menuData['business']; + if (!empty($biz['address']) && empty($biz['addressLine1'])) { + $addr = trim(preg_replace('/,?\s*(United States|USA|US|U\.S\.A?\.)\s*$/i', '', $biz['address'])); + // Extract ZIP + if (preg_match('/\b(\d{5})(?:-\d{4})?\s*$/', $addr, $zm)) { + $biz['zip'] = $zm[1]; + $addr = trim(substr($addr, 0, $zm[0] ? strrpos($addr, $zm[0]) : strlen($addr))); + } + // Extract state (2-letter code at end) + if (preg_match('/\b([A-Z]{2})\s*$/i', $addr, $sm)) { + $biz['state'] = strtoupper($sm[1]); + $addr = trim(substr($addr, 0, strrpos($addr, $sm[0]))); + } + // Split remaining into addressLine1 and city by comma + $addr = rtrim($addr, ', '); + if (strpos($addr, ',') !== false) { + $parts = array_map('trim', explode(',', $addr)); + $biz['addressLine1'] = $parts[0]; + $biz['city'] = $parts[1] ?? ''; + } + } + // Clean city if it still has state/zip/country in it + if (!empty($biz['city']) && strpos($biz['city'], ',') !== false) { + $biz['city'] = trim(explode(',', $biz['city'])[0]); + } + // Pass through menus array if Claude detected multiple menus if (!empty($menuData['menus']) && is_array($menuData['menus']) && count($menuData['menus']) > 1) { $response['steps'][] = "Detected " . count($menuData['menus']) . " separate menus: " . implode(', ', array_column($menuData['menus'], 'name'));