diff --git a/CHANGELOG.md b/CHANGELOG.md index 548b7ae..a1aeae1 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 86f43c3..9043978 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 2bec758..097f511 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 611e1a8..e09e6ca 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($carrierReference, $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 a26f3d7..d0620df 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 ba3dc8b..ee43983 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; }