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-319/ Carriers price rules fix [WIP] #123

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions dpdbaltics.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,18 @@ public function getOrderShippingCostExternal($cart)
$currentCountryProvider = $this->getModuleContainer('invertus.dpdbaltics.provider.current_country_provider');

$deliveryAddress = new Address($cart->id_address_delivery);
$carrier = new Carrier($this->id_carrier);

// if (empty($zoneRepository->findZoneInRangeByAddress($deliveryAddress))) {
// return false;
// }

$availableDpdProductsByZone = $zoneRepository->findProductsInZoneRange($deliveryAddress, $carrier->id_reference);

if (empty($zoneRepository->findZoneInRangeByAddress($deliveryAddress))) {
if (empty($availableDpdProductsByZone)) {
return false;
}

$carrier = new Carrier($this->id_carrier);

if (!$productAvailabilityService->checkIfCarrierIsAvailable($carrier->id_reference)) {
return false;
}
Expand Down
42 changes: 42 additions & 0 deletions src/Repository/ZoneRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,46 @@ public function findZoneInRangeByAddress(Address $address)

return $result ?: [];
}

public function findProductsInZoneRange(Address $address, string $carrierReference)
{
$idCountry = $address->id_country ?: (int)\Configuration::get('PS_COUNTRY_DEFAULT');
$zipCode = $address->postcode;

$query = new DbQuery();

$query->select('dp.*');
$query->from('dpd_product', 'dp');
$query->where('dp.id_reference = ' . pSql($carrierReference));
$query->where('dp.active = ' . (int) 1);
$query->where('dp.all_zones = ' . (int) 1);

$result = $this->db->executeS($query);

if (!empty($result)) {
return $result;
}

$query = new DbQuery();
$query->select('dp.*');
$query->from('dpd_zone', 'dz');
$query->leftJoin('dpd_zone_range', 'dzr', 'dzr.id_dpd_zone = dz.id_dpd_zone');
$query->leftJoin('dpd_product_zone', 'dpz', 'dpz.id_dpd_zone = dz.id_dpd_zone');
$query->leftJoin('dpd_product', 'dp', 'dp.id_dpd_product = dpz.id_dpd_product');

$query->where('dp.active = ' . (int) 1);
$query->where('dzr.id_country = ' . (int)$idCountry);
$query->where('dzr.include_all_zip_codes = 1 OR (dzr.zip_code_from_numeric <= \'' . pSQL($zipCode) . '\' AND dzr.zip_code_to_numeric >= \'' . pSQL($zipCode) . '\')');

$productsIdReferences = $this->db->executeS($query);
$result = [];

foreach($productsIdReferences as $product) {
if ($product['id_reference'] === $carrierReference) {
$result[] = $product['id_reference'];
}
}

return $result ?: [];
}
}
3 changes: 3 additions & 0 deletions src/Service/ShippingPriceCalculationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function __construct(
public function calculate(Cart $cart, \Carrier $carrier, Address $deliveryAddress)
{
$shippingCosts = 0.0;
//todo price rules do not exist if setting is all price rule exist
// if prz all zones = 1
// check if carrier set to all zones if yes we take price rule of the all_zones

$priceRulesIds = $this->priceRuleRepository->getByCarrierReference(
$deliveryAddress,
Expand Down
Loading