Skip to content

Commit

Permalink
Merge pull request #118 from Invertus/DGS-281/price-rules-fix
Browse files Browse the repository at this point in the history
DGS-281/ Price rules fix
  • Loading branch information
GytisZum authored Dec 12, 2023
2 parents 585fb44 + 32bd712 commit 2ed6f39
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 20 additions & 2 deletions src/Repository/PriceRuleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`');
Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/Service/ShippingPriceCalculationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 2ed6f39

Please sign in to comment.