Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DGS-281/ Price rules fix #118

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading