diff --git a/src/Service/PriceRuleService.php b/src/Service/PriceRuleService.php index fabbfef..b23bbc9 100644 --- a/src/Service/PriceRuleService.php +++ b/src/Service/PriceRuleService.php @@ -392,8 +392,12 @@ public function applyPriceRuleForCarrier(Cart $cart, $priceRulesIds, $shopId) { $availablePriceRules = $this->priceRuleRepository->findAllAvailableInShop($shopId); + if (!$availablePriceRules) { + return false; + } + foreach ($priceRulesIds as $priceRuleId) { - if (!in_array($priceRuleId, $availablePriceRules)) { + if (!$this->ensureCarrierHasPriceRule($priceRuleId, $availablePriceRules)) { return false; } @@ -429,4 +433,20 @@ private function duplicatePriceRuleTablesData($tables, $priceRuleTablesData, $ne return true; } + + /** + * @param string $priceRuleId + * @param array|false $availablePriceRules + * @return bool + */ + private function ensureCarrierHasPriceRule($priceRuleId, $availablePriceRules) + { + foreach ($availablePriceRules as $rule) { + if (isset($rule['id_dpd_price_rule']) && (int) $rule['id_dpd_price_rule'] === (int) $priceRuleId) { + return true; + } + } + + return false; + } }