From 6dca1fbc885d65944299db211f8a111ad18e8fed Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 16:20:16 +0200 Subject: [PATCH 1/3] fix: fixed post codes to check only numeric one --- src/Adapter/AddressAdapter.php | 7 ++++--- src/Repository/ZoneRepository.php | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Adapter/AddressAdapter.php b/src/Adapter/AddressAdapter.php index 6c8f47ea..27aec1d9 100644 --- a/src/Adapter/AddressAdapter.php +++ b/src/Adapter/AddressAdapter.php @@ -85,9 +85,10 @@ private function getFormattedZipCode(Country $country, $postCode) $postCode = preg_replace("/[^a-zA-Z0-9]+/", "", $postCode); // If C doesn't exist in zip code format - don't modify the zip code - if (false === $countryCodePosition) { - return $postCode; - } + //todo this check prevents from saving zip code to numeric not sure why c has to be checked +// if (false === $countryCodePosition) { +// return $postCode; +// } $countryCodeLength = Tools::strlen($country->iso_code); $countryCode = Tools::substr($postCode, $countryCodePosition, $countryCodeLength); diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index a26f3d77..c1cd4102 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,6 +24,7 @@ use Address; use Country; use DbQuery; +use Invertus\dpdBaltics\Adapter\AddressAdapter; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -101,14 +102,16 @@ public function addProductZonesFromArray(array $zones) public function findZoneInRangeByAddress(Address $address) { $idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); - $zipCode = $address->postcode; + $addressAdapter = new AddressAdapter(); + + $zipCode = $addressAdapter->getZipCodeByCountry($idCountry, $address->postcode); $query = new DbQuery(); $query->select('dz.id_dpd_zone'); $query->from('dpd_zone', 'dz'); $query->leftJoin('dpd_zone_range', 'dzr', 'dzr.id_dpd_zone = dz.id_dpd_zone'); $query->where('dzr.id_country = ' . (int)$idCountry); - $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to >= \'' . pSQL($zipCode) . '\')'); + $query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from_numeric <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to_numeric >= \'' . pSQL($zipCode) . '\')'); $result = $this->db->executeS($query); From 0f7f5b73dd7ee6a36588f70815184541f4f65046 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 17:20:01 +0200 Subject: [PATCH 2/3] restore country code check --- src/Adapter/AddressAdapter.php | 7 +++---- src/Repository/ZoneRepository.php | 5 ++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Adapter/AddressAdapter.php b/src/Adapter/AddressAdapter.php index 27aec1d9..6c8f47ea 100644 --- a/src/Adapter/AddressAdapter.php +++ b/src/Adapter/AddressAdapter.php @@ -85,10 +85,9 @@ private function getFormattedZipCode(Country $country, $postCode) $postCode = preg_replace("/[^a-zA-Z0-9]+/", "", $postCode); // If C doesn't exist in zip code format - don't modify the zip code - //todo this check prevents from saving zip code to numeric not sure why c has to be checked -// if (false === $countryCodePosition) { -// return $postCode; -// } + if (false === $countryCodePosition) { + return $postCode; + } $countryCodeLength = Tools::strlen($country->iso_code); $countryCode = Tools::substr($postCode, $countryCodePosition, $countryCodeLength); diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index c1cd4102..b19169a2 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -25,6 +25,7 @@ use Country; use DbQuery; use Invertus\dpdBaltics\Adapter\AddressAdapter; +use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -102,9 +103,7 @@ public function addProductZonesFromArray(array $zones) public function findZoneInRangeByAddress(Address $address) { $idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); - $addressAdapter = new AddressAdapter(); - - $zipCode = $addressAdapter->getZipCodeByCountry($idCountry, $address->postcode); + $zipCode = ZoneRangeValidate::getNumericZipCode($address->postcode, $idCountry); $query = new DbQuery(); $query->select('dz.id_dpd_zone'); From 9f88532fa3e298db700a3433c0a1b9ff112f914e Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 14 Mar 2024 10:57:36 +0200 Subject: [PATCH 3/3] unused use statement deleted --- src/Repository/ZoneRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index b19169a2..d0620df8 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,7 +24,6 @@ use Address; use Country; use DbQuery; -use Invertus\dpdBaltics\Adapter\AddressAdapter; use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException;