Skip to content

Commit 8a1a4d7

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

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

phpstan-bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
define('GF_BAG_FILE', 'plugin.php');
55
define('GF_BAG_SLUG', 'owc-gravityforms-bag-address');
66
define('GF_BAG_ROOT_PATH', './');
7-
define('GF_BAG_VERSION', '1.1.6');
7+
define('GF_BAG_VERSION', '1.1.7');

plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Add a BAG address field to GravityForms.
66
* Author: Yard | Digital Agency
77
* Author URI: https://www.yard.nl
8-
* Version: 1.1.6
8+
* Version: 1.1.7
99
* License: GPL3.0
1010
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
1111
* Text Domain: owc-gravityforms-bag-address
@@ -23,7 +23,7 @@
2323
define('GF_BAG_SLUG', 'owc-gravityforms-bag-address');
2424
define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG);
2525
define('GF_BAG_ROOT_PATH', __DIR__);
26-
define('GF_BAG_VERSION', '1.1.6');
26+
define('GF_BAG_VERSION', '1.1.7');
2727

2828
/**
2929
* Manual loaded file: the autoloader.

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')),

tests/Unit/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG);
2525
define('GF_BAG_DIR', basename(__DIR__));
2626
define('GF_BAG_ROOT_PATH', __DIR__);
27-
define('GF_BAG_VERSION', '1.1.6');
27+
define('GF_BAG_VERSION', '1.1.7');
2828

2929
/**
3030
* Bootstrap WordPress Mock.

0 commit comments

Comments
 (0)