diff --git a/CHANGELOG.md b/CHANGELOG.md index b316804..f57ac8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -154,3 +154,7 @@ ## [3.2.17] - Label printing after changing shipment product bug fix + +## [3.2.18] +- Vulnerability fix with development dependencies +- Price rule bug fix to add additional filtration by country \ No newline at end of file diff --git a/dpdbaltics.php b/dpdbaltics.php index cb11ea4..b1adf47 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.17'; + $this->version = '3.2.18'; $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; $this->need_instance = 0; parent::__construct(); diff --git a/src/Repository/PriceRuleRepository.php b/src/Repository/PriceRuleRepository.php index ce71fda..365ed6a 100644 --- a/src/Repository/PriceRuleRepository.php +++ b/src/Repository/PriceRuleRepository.php @@ -73,12 +73,14 @@ public function getAllFlag($tableName, $idPriceRule) * * @param Address $deliveryAddress * @param int $carrierReferenceId + * @param bool $includeCountryCheck * @return array price rules IDs * @throws PrestaShopDatabaseException */ public function getByCarrierReference( Address $deliveryAddress, - $carrierReference + $carrierReference, + bool $includeCountryCheck = false ) { $query = new DbQuery(); $query->select('prc.`id_dpd_price_rule`'); @@ -89,11 +91,27 @@ public function getByCarrierReference( 'prs', 'prs.`id_dpd_price_rule` = prc.`id_dpd_price_rule`' ); + + /* param needed to filter out by countries to get specific price rules for that country address */ + if ($includeCountryCheck) { + $query->innerJoin( + 'dpd_price_rule_zone', + 'prz', + 'prc.`id_dpd_price_rule` = prz.`id_dpd_price_rule`' + ); + $query->innerJoin( + 'dpd_zone_range', + 'zr', + 'prz.`id_dpd_zone` = zr.`id_dpd_zone`' + ); + + $query->where('zr.`id_country`= ' . $deliveryAddress->id_country); + } + $query->where('prc.`id_reference`="' . (int)$carrierReference . '" OR prc.`all_carriers`="1"'); $query->where('pr.active = 1'); $query->orderBy('pr.position ASC'); - if (Validate::isLoadedObject($deliveryAddress)) { if ($deliveryAddress->company) { $query->where( diff --git a/src/Service/ShippingPriceCalculationService.php b/src/Service/ShippingPriceCalculationService.php index 2e69655..1bbc8e3 100644 --- a/src/Service/ShippingPriceCalculationService.php +++ b/src/Service/ShippingPriceCalculationService.php @@ -56,7 +56,8 @@ public function calculate(Cart $cart, \Carrier $carrier, Address $deliveryAddres $priceRulesIds = $this->priceRuleRepository->getByCarrierReference( $deliveryAddress, - $carrier->id_reference + $carrier->id_reference, + true ); $shippingCosts += $this->priceRuleService->applyPriceRuleForCarrier(