Skip to content

Commit

Permalink
Merge pull request #124 from Invertus/DGS-287/numeric-postcode
Browse files Browse the repository at this point in the history
DGS-287/ fixed post codes to check only numeric one
  • Loading branch information
GytisZum authored Mar 14, 2024
2 parents ece885c + 9f88532 commit eabf8b3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 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\Validate\Zone\ZoneRangeValidate;
use PrestaShopDatabaseException;

class ZoneRepository extends AbstractEntityRepository
Expand Down Expand Up @@ -101,14 +102,14 @@ public function addProductZonesFromArray(array $zones)
public function findZoneInRangeByAddress(Address $address)
{
$idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT');
$zipCode = $address->postcode;
$zipCode = ZoneRangeValidate::getNumericZipCode($address->postcode, $idCountry);

$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 eabf8b3

Please sign in to comment.