Skip to content

Commit

Permalink
Merge pull request #112 from Invertus/price-rules-fix
Browse files Browse the repository at this point in the history
Fixed price rules
  • Loading branch information
GytisZum authored Oct 17, 2023
2 parents 502bce5 + 1987714 commit 7953f27
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Service/PriceRuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}

0 comments on commit 7953f27

Please sign in to comment.