Skip to content

Commit 7fc7f11

Browse files
committed
fix: return result with no addition if not provided
1 parent 6ca0633 commit 7fc7f11

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/BAG/GravityForms/BAGAddress/BAGLookup.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,32 @@ protected function processResponse($response): string
8787
]);
8888
}
8989

90+
// If no addition was provided, try to find the result without any addition
91+
if ($this->homeNumberAddition === '') {
92+
$exactMatch = null;
93+
94+
foreach ($response->docs as $doc) {
95+
if (!isset($doc->huisnummertoevoeging) && !isset($doc->huisletter)) {
96+
$exactMatch = $doc;
97+
break;
98+
}
99+
}
100+
101+
if ($exactMatch !== null) {
102+
$address = new BAGEntity($exactMatch);
103+
return \wp_send_json_success([
104+
'message' => __('1 result found', config('core.text_domain')),
105+
'results' => [
106+
'street' => $address->straatnaam,
107+
'houseNumber' => $address->huisnummer,
108+
'city' => $address->woonplaatsnaam,
109+
'zip' => $address->postcode,
110+
'displayname' => $address->weergavenaam
111+
]
112+
]);
113+
}
114+
}
115+
90116
return wp_send_json_error(
91117
[
92118
'message' => __('Found too many results. Try to make the address more specific. For example with a house number addition', config('core.text_domain')),

0 commit comments

Comments
 (0)