From a1a17f4978cbab1cb90f723293545f0d5abea17f Mon Sep 17 00:00:00 2001 From: Stas Demin Date: Mon, 17 Jun 2024 15:29:48 +0300 Subject: [PATCH 1/2] fix: merge insert services instead to rewrite services by get services from delivery settings --- src/Helpers/DeliveryCalc.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Helpers/DeliveryCalc.php b/src/Helpers/DeliveryCalc.php index a556a31..d6d9483 100644 --- a/src/Helpers/DeliveryCalc.php +++ b/src/Helpers/DeliveryCalc.php @@ -156,11 +156,14 @@ static function ($carry, $item) use ($package) { $api = $this->api; $deliveryMethod = $this->method; + $servicesParams = $deliveryParam['services']; + $this->rates = array_map(static function ($tariff) use ( $priceRules, $api, $deliveryParam, - $deliveryMethod + $deliveryMethod, + $servicesParams ) { $rule = Tariff::isTariffToOffice($tariff['meta_data'][MetaKeys::TARIFF_CODE]) ? $priceRules['office'] : $priceRules['door']; @@ -181,8 +184,9 @@ static function ($carry, $item) use ($package) { $deliveryParam['type'] = Tariff::getTariffType($deliveryParam['tariff_code']); $serviceList = Helper::getServices($deliveryMethod, $deliveryParam['tariff_code']); + if (!empty($serviceList)) { - $deliveryParam['services'] = $serviceList; + $deliveryParam['services'] = array_merge($serviceList, $servicesParams); } $tariffInfo = $api->calculateTariff($deliveryParam); From e5683a1e3eba108ff2643594adeeb2f77ace72cf Mon Sep 17 00:00:00 2001 From: Stas Demin Date: Mon, 17 Jun 2024 15:29:48 +0300 Subject: [PATCH 2/2] fix: remove not necessary variables --- src/Helpers/DeliveryCalc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Helpers/DeliveryCalc.php b/src/Helpers/DeliveryCalc.php index a556a31..d8aec52 100644 --- a/src/Helpers/DeliveryCalc.php +++ b/src/Helpers/DeliveryCalc.php @@ -181,8 +181,9 @@ static function ($carry, $item) use ($package) { $deliveryParam['type'] = Tariff::getTariffType($deliveryParam['tariff_code']); $serviceList = Helper::getServices($deliveryMethod, $deliveryParam['tariff_code']); + if (!empty($serviceList)) { - $deliveryParam['services'] = $serviceList; + $deliveryParam['services'] = array_merge($serviceList, $deliveryParam['services']); } $tariffInfo = $api->calculateTariff($deliveryParam);