From 0f7f5b73dd7ee6a36588f70815184541f4f65046 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 17:20:01 +0200 Subject: [PATCH] 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');