From e7115d2e7686fb81f1579fc087a22ac4754a0c77 Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 11 Dec 2023 13:54:46 +0200 Subject: [PATCH 1/2] added additional filtration for the price rules which includes check of the country --- src/Repository/PriceRuleRepository.php | 22 +++++++++++++++++-- .../ShippingPriceCalculationService.php | 3 ++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Repository/PriceRuleRepository.php b/src/Repository/PriceRuleRepository.php index ce71fdae..365ed6a6 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 2e696558..1bbc8e3f 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( From 32bd71260bd01a5e975b4fa92cbfdb105e60f49a Mon Sep 17 00:00:00 2001 From: Gytautas Date: Mon, 11 Dec 2023 13:59:02 +0200 Subject: [PATCH 2/2] version increased and changelog updated --- CHANGELOG.md | 4 ++++ dpdbaltics.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3168040..f57ac8eb 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 cb11ea4f..b1adf47e 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();