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 <noreply@anthropic.com>
This commit is contained in:
parent
a7464545df
commit
552c404cf6
1 changed files with 27 additions and 0 deletions
|
|
@ -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'));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue