Skip to content

Commit

Permalink
fix: fixed post codes to check only numeric one
Browse files Browse the repository at this point in the history
  • Loading branch information
GytisZum committed Feb 29, 2024
1 parent 220eb4e commit 6dca1fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Adapter/AddressAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions src/Repository/ZoneRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Address;
use Country;
use DbQuery;
use Invertus\dpdBaltics\Adapter\AddressAdapter;
use PrestaShopDatabaseException;

class ZoneRepository extends AbstractEntityRepository
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6dca1fb

Please sign in to comment.