Skip to content

Commit

Permalink
Merge pull request #120 from Invertus/DGS-310/carrier-availability-co…
Browse files Browse the repository at this point in the history
…untry-fix

DGS-310/ Carrier availability in country
  • Loading branch information
GytisZum authored Feb 20, 2024
2 parents a3a7ee1 + 71ce134 commit 220eb4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
38 changes: 38 additions & 0 deletions src/Repository/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(int $carrierReference, int $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);
}
}

0 comments on commit 220eb4e

Please sign in to comment.