From 99ede447482c6eee73fd6e54bb72ad98c1984324 Mon Sep 17 00:00:00 2001 From: taylormadeapps <ttaylor@encircle.co.uk> Date: Mon, 12 Feb 2024 17:53:47 +0000 Subject: [PATCH] Fixed OS Places API returning non postal addresses. --- CRM/Civicrmpostcodelookup/Page/OsPlacesApi.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/CRM/Civicrmpostcodelookup/Page/OsPlacesApi.php b/CRM/Civicrmpostcodelookup/Page/OsPlacesApi.php index 8560ac2..77b3521 100644 --- a/CRM/Civicrmpostcodelookup/Page/OsPlacesApi.php +++ b/CRM/Civicrmpostcodelookup/Page/OsPlacesApi.php @@ -26,7 +26,6 @@ class CRM_Civicrmpostcodelookup_Page_OsPlacesApi extends CRM_Civicrmpostcodelook } $addressList = \Civi::cache('long')->get("ukpostcodes_{$postcode}") ?? NULL; - $addressList = NULL; if (!isset($addressList)) { // get address result from getAddress.io $apiUrl = self::osPlacesApiUrl($postcode); @@ -192,21 +191,17 @@ class CRM_Civicrmpostcodelookup_Page_OsPlacesApi extends CRM_Civicrmpostcodelook } $postcode = self::format($postcode, TRUE); $AddressListItem = $addressData['results']; + $record_id=0; foreach ($AddressListItem as $key => $addressItem) { + if($addressItem["LPI"]["POSTAL_ADDRESS_CODE"]=='N'){ + continue; + } + $addressId = $postcode . '_' . $record_id; - // FIX me : There is no address id found in th API, hence assigning combination of postcode & arrayresultID as rowId inorder to get the selected address later - $addressId = $postcode . '_' . $key; + $record_id++; $addressLineArray = self::formatAddressLines($addressId, $addressItem["LPI"]); - /*$addressLineLabelArray = $addressLineArray; - unset($addressLineLabelArray['country_id']); - unset($addressLineLabelArray['state_province_id']); - unset($addressLineLabelArray['country']);*/ - - // Don't display country_id in address list - - //$addressLineArray['postcode'] = $postcode; $addressRow['id'] = $addressId; $addressRow['value'] = $postcode; -- GitLab