From defb608341370984f21b17d56a7018efc3d9c765 Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:56:39 +0300 Subject: [PATCH 1/2] Release v3.2.19 (#82) (#83) * hide print label button in orders listing page * fix: translation domain added * fix: moved dev dependency from production ones * added additional filtration for the price rules which includes check of the country * version increased and changelog updated * feat: upgrade method created to define value * price rule and country fix * carrier availability in country fox * not needed use statement removed * fix: fixed to check all countries too * added additional filtration to filter active countries only * modal fix for more information * fix: fixed post codes to check only numeric one * restore country code check * unused use statement deleted * version bump and changelogs added --- CHANGELOG.md | 6 ++++ dpdbaltics.php | 16 ++++++---- src/Repository/PhonePrefixRepository.php | 2 ++ src/Repository/ProductRepository.php | 38 ++++++++++++++++++++++++ src/Repository/ZoneRepository.php | 5 ++-- views/js/front/pudo-search.js | 2 +- 6 files changed, 60 insertions(+), 9 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 86f43c38..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' ] ); @@ -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)) { @@ -502,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; } @@ -1145,7 +1150,6 @@ private function updateOrderCarrier($shipmentId) public function hookDisplayOrderDetail($params) { - $isReturnServiceEnabled = Configuration::get(Config::PARCEL_RETURN); if (!$isReturnServiceEnabled) { return; @@ -1274,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')) 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)) { diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index 611e1a82..35954d16 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -252,4 +252,42 @@ 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 + */ + public function checkIfCarrierIsAvailableInCountry(int $carrierReference, int $countryId) + { + $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'); + + $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); + } } diff --git a/src/Repository/ZoneRepository.php b/src/Repository/ZoneRepository.php index a26f3d77..d0620df8 100644 --- a/src/Repository/ZoneRepository.php +++ b/src/Repository/ZoneRepository.php @@ -24,6 +24,7 @@ use Address; use Country; use DbQuery; +use Invertus\dpdBaltics\Validate\Zone\ZoneRangeValidate; use PrestaShopDatabaseException; class ZoneRepository extends AbstractEntityRepository @@ -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); 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 0a2c7449ca3906ae9d3d6ccf62e696a400ba987f Mon Sep 17 00:00:00 2001 From: Gytautas Zumaras <96050852+GytisZum@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:30:20 +0300 Subject: [PATCH 2/2] Update ProductRepository.php --- src/Repository/ProductRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Repository/ProductRepository.php b/src/Repository/ProductRepository.php index cb83b9b0..e09e6ca2 100644 --- a/src/Repository/ProductRepository.php +++ b/src/Repository/ProductRepository.php @@ -260,7 +260,6 @@ public function findProductByProductReference($carrierReference) * @return array|bool|mysqli_result|PDOStatement|resource|null * @throws PrestaShopDatabaseException */ - public function checkIfCarrierIsAvailableInCountry($carrierReference, $countryId) { $productId = $this->getProductIdByCarrierReference($carrierReference);