forked from DPDBaltics/PrestaShop-1.7
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from Invertus/DGS-319/revert-changes-zones-fa…
…ilure DGS-319 Revert changes that broke zones logic
- Loading branch information
Showing
7 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
services: | ||
_defaults: | ||
public: true | ||
|
||
invertus.dpdbaltics.verification.is_address_in_zone: | ||
class: 'Invertus\dpdBaltics\Verification\IsAddressInZone' | ||
arguments: | ||
- '@invertus.dpdbaltics.repository.zone_range_repository' | ||
- '@invertus.dpdbaltics.verification.is_address_in_range' | ||
|
||
invertus.dpdbaltics.verification.is_address_in_range: | ||
class: 'Invertus\dpdBaltics\Verification\IsAddressInRange' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
/** | ||
* NOTICE OF LICENSE | ||
* | ||
* @author INVERTUS, UAB www.invertus.eu <[email protected]> | ||
* @copyright Copyright (c) permanent, INVERTUS, UAB | ||
* @license Addons PrestaShop license limitation | ||
* @see /LICENSE | ||
* | ||
* International Registered Trademark & Property of INVERTUS, UAB | ||
*/ | ||
|
||
namespace Invertus\dpdBaltics\Verification; | ||
|
||
use Invertus\dpdBaltics\Repository\ZoneRangeRepository; | ||
use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; | ||
|
||
class IsAddressInRange | ||
{ | ||
/** | ||
* Check if address falls into given zones | ||
* | ||
* @param \Address $address | ||
* @param array $zones | ||
* | ||
* @return bool | ||
* @throws \PrestaShopDatabaseException | ||
* @throws \PrestaShopException | ||
*/ | ||
public function verify(\Address $address, array $range) | ||
{ | ||
$idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); | ||
|
||
//NOTE: if countries do not match, we continue. | ||
if ((int) $idCountry !== (int) $address->id_country) { | ||
return false; | ||
} | ||
|
||
if ($range['include_all_zip_codes']) { | ||
return true; | ||
} | ||
|
||
if (ZoneRangeValidate::isZipCodeInRange( | ||
$address->postcode, | ||
$range['zip_code_from'], | ||
$range['zip_code_to'], | ||
$idCountry | ||
)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* NOTICE OF LICENSE | ||
* | ||
* @author INVERTUS, UAB www.invertus.eu <[email protected]> | ||
* @copyright Copyright (c) permanent, INVERTUS, UAB | ||
* @license Addons PrestaShop license limitation | ||
* @see /LICENSE | ||
* | ||
* International Registered Trademark & Property of INVERTUS, UAB | ||
*/ | ||
|
||
namespace Invertus\dpdBaltics\Verification; | ||
|
||
use Invertus\dpdBaltics\Repository\ZoneRangeRepository; | ||
use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; | ||
|
||
class IsAddressInZone | ||
{ | ||
/** | ||
* @var ZoneRangeRepository | ||
*/ | ||
private $zoneRangeRepository; | ||
/** | ||
* @var IsAddressInRange | ||
*/ | ||
private $isAddressInRange; | ||
|
||
public function __construct( | ||
ZoneRangeRepository $zoneRangeRepository, | ||
IsAddressInRange $isAddressInRange | ||
) { | ||
$this->zoneRangeRepository = $zoneRangeRepository; | ||
$this->isAddressInRange = $isAddressInRange; | ||
} | ||
|
||
/** | ||
* Check if address falls into given zones | ||
* | ||
* @param \Address $address | ||
* @param array $zones | ||
* | ||
* @return bool | ||
* @throws \PrestaShopDatabaseException | ||
* @throws \PrestaShopException | ||
*/ | ||
public function verify(\Address $address, array $zones) | ||
{ | ||
$idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT'); | ||
|
||
foreach ($zones as $zone) { | ||
// Get ranges by zone and country | ||
$ranges = $this->zoneRangeRepository->findBy([ | ||
'id_dpd_zone' => $zone['id'], | ||
// Check by country as well, because the zone must match the country of address | ||
'id_country' => $idCountry, | ||
]); | ||
|
||
if (empty($ranges)) { | ||
continue; | ||
} | ||
|
||
foreach ($ranges as $range) { | ||
if ($this->isAddressInRange->verify($address, $range)) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); | ||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); | ||
|
||
header("Cache-Control: no-store, no-cache, must-revalidate"); | ||
header("Cache-Control: post-check=0, pre-check=0", false); | ||
header("Pragma: no-cache"); | ||
|
||
header("Location: ../"); | ||
exit; |