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);