From e4655f6d6a79dcee84d95bc4d74856a60a36d6b2 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 11 Jan 2024 14:04:41 +0200 Subject: [PATCH 01/10] carrier availability in country fox --- dpdbaltics.php | 5 ++++ src/Repository/ProductRepository.php | 38 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/dpdbaltics.php b/dpdbaltics.php index 86f43c38..e22b3855 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -475,6 +475,11 @@ public function getOrderShippingCostExternal($cart) return false; } + if (!$productRepo->checkIfCarrierIsAvailableInCountry((int) $carrier->id_reference, (int) $deliveryAddress->id_country) + ) { + return false; + } + try { $isCarrierAvailableInShop = $productRepo->checkIfCarrierIsAvailableInShop($carrier->id_reference, $this->context->shop->id); if (empty($isCarrierAvailableInShop)) { diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 611e1a82..fe488f29 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -28,6 +28,8 @@ use PDOStatement; use PrestaShopCollection; use PrestaShopDatabaseException; +use PrestaShopException; +use resource; class ProductRepository extends AbstractEntityRepository { @@ -252,4 +254,40 @@ public function findProductByProductReference($carrierReference) return $this->db->getRow($query) ?: null; } + + + /** + * @param int $carrierReference + * @param int $countryId + * + * @return array|bool|mysqli_result|PDOStatement|resource|null + * @throws PrestaShopDatabaseException + * @throws PrestaShopException + */ + public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) + { + $productId = $this->getProductIdByCarrierReference($carrierReference); + $product = new DPDProduct($productId); + + $query = new DbQuery(); + $query->select('dp.id_dpd_product'); + $query->from('dpd_product', 'dp'); + + $query->leftJoin( + 'dpd_product_zone', + 'dpz', + 'dp.`id_dpd_product` = dpz.`id_dpd_product`' + ); + + $query->leftJoin( + 'dpd_zone_range', + 'dzr', + 'dzr.`id_dpd_zone` = dpz.`id_dpd_zone`' + ); + + $query->where('dp.id_reference= '.(int) $product->id_reference); + $query->where('dzr.id_country = '.(int) $countryId); + + return $this->db->executeS($query); + } } From f9d11e3d5ce8f63ed9a6fd09d85f0c7b2dc8db6b Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 11 Jan 2024 14:06:31 +0200 Subject: [PATCH 02/10] not needed use statement removed --- src/Repository/ProductRepository.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index fe488f29..a2592ced 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -28,8 +28,6 @@ use PDOStatement; use PrestaShopCollection; use PrestaShopDatabaseException; -use PrestaShopException; -use resource; class ProductRepository extends AbstractEntityRepository { @@ -255,14 +253,12 @@ public function findProductByProductReference($carrierReference) return $this->db->getRow($query) ?: null; } - /** * @param int $carrierReference * @param int $countryId * * @return array|bool|mysqli_result|PDOStatement|resource|null * @throws PrestaShopDatabaseException - * @throws PrestaShopException */ public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) { From 71ce134fe2c4598de73d3612566f603c6c3ca21e Mon Sep 17 00:00:00 2001 From: Gytautas Date: Fri, 19 Jan 2024 09:36:12 +0200 Subject: [PATCH 03/10] fix: fixed to check all countries too --- src/Repository/ProductRepository.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index a2592ced..35954d16 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -265,6 +265,10 @@ public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $c $productId = $this->getProductIdByCarrierReference($carrierReference); $product = new DPDProduct($productId); + if ($product->all_zones) { + return ['id_dpd_product' => $productId]; + } + $query = new DbQuery(); $query->select('dp.id_dpd_product'); $query->from('dpd_product', 'dp'); From ede5164043893163e2302488d93438b9af82a701 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Fri, 19 Jan 2024 14:32:01 +0200 Subject: [PATCH 04/10] added additional filtration to filter active countries only --- src/Repository/PhonePrefixRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Repository/PhonePrefixRepository.php b/src/Repository/PhonePrefixRepository.php index 2bec758f..097f511b 100644 --- a/src/Repository/PhonePrefixRepository.php +++ b/src/Repository/PhonePrefixRepository.php @@ -57,6 +57,8 @@ public function getCallPrefixesFrontOffice() $query = new DbQuery(); $query->select('c.`call_prefix`'); $query->from('country', 'c'); + $query->where('active=1'); + $resource = Db::getInstance()->query($query); $result = []; while ($row = Db::getInstance()->nextRow($resource)) { From c595738ef9b9e4d607890cac8e745181827efac6 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Fri, 19 Jan 2024 14:45:02 +0200 Subject: [PATCH 05/10] modal fix for more information --- views/js/front/pudo-search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/js/front/pudo-search.js b/views/js/front/pudo-search.js index ba3dc8be..ee43983b 100644 --- a/views/js/front/pudo-search.js +++ b/views/js/front/pudo-search.js @@ -137,7 +137,7 @@ function saveSelectedStreet(city, street) { var coordinates = response.coordinates; var $idReference = $parent.data('id'); $('.points-container').empty().append(response.template); - + reselectDataPopover(); initMap(coordinates, true, response.selectedPudoId, false, $idReference); isPudoPointSelected = true; } From 6dca1fbc885d65944299db211f8a111ad18e8fed Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 16:20:16 +0200 Subject: [PATCH 06/10] fix: fixed post codes to check only numeric one --- src/Adapter/AddressAdapter.php | 7 ++++--- src/Repository/ZoneRepository.php | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) 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); From 0f7f5b73dd7ee6a36588f70815184541f4f65046 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 29 Feb 2024 17:20:01 +0200 Subject: [PATCH 07/10] 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'); From 9f88532fa3e298db700a3433c0a1b9ff112f914e Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 14 Mar 2024 10:57:36 +0200 Subject: [PATCH 08/10] unused use statement deleted --- src/Repository/ZoneRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index b19169a2..d0620df8 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,7 +24,6 @@ use Address; use Country; use DbQuery; -use Invertus\dpdBaltics\Adapter\AddressAdapter; use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; From 0be83918adcdb0ba8bf7eee9ffbc4d5ff0cdbb85 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 14 Mar 2024 16:45:20 +0200 Subject: [PATCH 09/10] version bump and changelogs added --- CHANGELOG.md | 6 ++++++ dpdbaltics.php | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 548b7aed..a1aeae13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,3 +159,9 @@ - Ability to hide label print feature in orders list page - Vulnerability fix with development dependencies - Price rule bug fix to add additional filtration by country + +## [3.2.19] +- Carrier availability in country +- Phone input selections sorted by active countries in shop +- Work hours pop up fix +- Numeric post code improvements \ No newline at end of file diff --git a/dpdbaltics.php b/dpdbaltics.php index e22b3855..9043978f 100644 --- a/dpdbaltics.php +++ b/dpdbaltics.php @@ -92,7 +92,7 @@ public function __construct() $this->author = 'Invertus'; $this->tab = 'shipping_logistics'; $this->description = 'DPD Baltics shipping integration'; - $this->version = '3.2.18'; + $this->version = '3.2.19'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); @@ -203,7 +203,6 @@ public function hookActionFrontControllerSetMedia() 'priority' => 130 ] ); - } /** @var \Invertus\dpdBaltics\Provider\CurrentCountryProvider $currentCountryProvider */ @@ -278,7 +277,8 @@ public function hookActionFrontControllerSetMedia() $googleApiService = $this->getModuleContainer('invertus.dpdbaltics.service.google_api_service'); $this->context->controller->registerJavascript( 'dpdbaltics-google-api', - $googleApiService->getFormattedGoogleMapsUrl(), [ + $googleApiService->getFormattedGoogleMapsUrl(), + [ 'server' => 'remote' ] ); @@ -507,7 +507,7 @@ public function getOrderShippingCostExternal($cart) $parcelDistribution = \Configuration::get(Config::PARCEL_DISTRIBUTION); $maxAllowedWeight = Config::getDefaultServiceWeights($countryCode, $serviceCarrier['product_reference']); - if (!$cartWeightValidator->validate($cart, $parcelDistribution ,$maxAllowedWeight)) { + if (!$cartWeightValidator->validate($cart, $parcelDistribution, $maxAllowedWeight)) { return false; } @@ -1150,7 +1150,6 @@ private function updateOrderCarrier($shipmentId) public function hookDisplayOrderDetail($params) { - $isReturnServiceEnabled = Configuration::get(Config::PARCEL_RETURN); if (!$isReturnServiceEnabled) { return; @@ -1279,7 +1278,7 @@ public function hookActionOrderGridDefinitionModifier(array $params) $definition = $params['definition']; if (!(bool) Configuration::get(Config::HIDE_ORDERS_LABEL_PRINT_BUTTON)) { - $definition->getColumns() + $definition->getColumns() ->addAfter( 'date_add', (new ActionColumn('dpd_print_label')) From 48439b3a1ce2dae36c191299a9282711e79ce463 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Thu, 18 Apr 2024 13:19:57 +0300 Subject: [PATCH 10/10] compatibility fix --- src/Repository/ProductRepository.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 35954d16..e09e6ca2 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -260,7 +260,7 @@ public function findProductByProductReference($carrierReference) * @return array|bool|mysqli_result|PDOStatement|resource|null * @throws PrestaShopDatabaseException */ - public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) + public function checkIfCarrierIsAvailableInCountry($carrierReference, $countryId) { $productId = $this->getProductIdByCarrierReference($carrierReference); $product = new DPDProduct($productId);