diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index 041c8f4..ce87fe8 100644 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -4,4 +4,4 @@ define('GF_BAG_FILE', 'plugin.php'); define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_ROOT_PATH', './'); -define('GF_BAG_VERSION', '1.1.3'); +define('GF_BAG_VERSION', '1.1.6'); diff --git a/plugin.php b/plugin.php index 9c753a1..3ffd6b4 100644 --- a/plugin.php +++ b/plugin.php @@ -5,7 +5,7 @@ * Description: Add a BAG address field to GravityForms. * Author: Yard | Digital Agency * Author URI: https://www.yard.nl - * Version: 1.1.5 + * Version: 1.1.6 * License: GPL3.0 * License URI: https://www.gnu.org/licenses/gpl-3.0.txt * Text Domain: owc-gravityforms-bag-address @@ -23,7 +23,7 @@ define('GF_BAG_SLUG', 'owc-gravityforms-bag-address'); define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.5'); +define('GF_BAG_VERSION', '1.1.6'); /** * Manual loaded file: the autoloader. diff --git a/src/BAG/GravityForms/BAGAddress/BAGLookup.php b/src/BAG/GravityForms/BAGAddress/BAGLookup.php index 5e6c1c5..1e7d952 100644 --- a/src/BAG/GravityForms/BAGAddress/BAGLookup.php +++ b/src/BAG/GravityForms/BAGAddress/BAGLookup.php @@ -111,34 +111,35 @@ public static function make(): self * @return string */ private function parseURLvariables(): string - { - $params = [ - 'postcode' => $this->zip, - 'type' => 'adres' - ]; - - if (empty($this->homeNumberAddition)) { - $params = array_merge($params, [ - 'huis_nlt' => $this->homeNumber, - ]); - } else { - $params = array_merge($params, [ - 'huisnummer' => $this->homeNumber, - 'huisletter' => $this->homeNumberAddition, - ]); - } + { + $arg_and = ['type:adres']; + $arg_or = []; - $filteredParameters = array_filter( - $params, - function ($item) { - return !empty($item); - } - ); + if (!empty($this->zip)) { + $arg_and[] = "postcode:{$this->zip}"; + } - $query = http_build_query($filteredParameters, null, '%20and%20'); - $query = str_replace('=', ':', $query); - return sprintf('%s%s', $this->url, $query); - } + if (!empty($this->homeNumber)) { + $arg_and[] = "huisnummer:{$this->homeNumber}"; + } + + if (!empty($this->homeNumberAddition)) { + $addition = strtoupper($this->homeNumberAddition); + + $arg_or[] = [ + "huisnummertoevoeging:{$addition}", + "huisletter:{$addition}", + ]; + } + + $arg_or = array_map(function ($group) { + return '( ' . implode(' or ', $group) . ' )'; + }, $arg_or); + + $query = implode(' and ', array_merge($arg_and, $arg_or)); + + return $this->url . urlencode($query); + } /** * Actually execute the remote request. diff --git a/tests/Unit/bootstrap.php b/tests/Unit/bootstrap.php index 4b61444..76c2f39 100644 --- a/tests/Unit/bootstrap.php +++ b/tests/Unit/bootstrap.php @@ -24,7 +24,7 @@ define('GF_BAG_LANGUAGE_DOMAIN', GF_BAG_SLUG); define('GF_BAG_DIR', basename(__DIR__)); define('GF_BAG_ROOT_PATH', __DIR__); -define('GF_BAG_VERSION', '1.1.3'); +define('GF_BAG_VERSION', '1.1.6'); /** * Bootstrap WordPress Mock.