fix subtotal always being used

This commit is contained in:
Joel Male
2024-09-23 07:45:59 +10:00
parent 472d505041
commit 5505f121c7
2 changed files with 7 additions and 6 deletions
+6 -5
View File
@@ -458,9 +458,6 @@ public function removeItemCondition($itemId, $conditionName)
}
}
// reset indexes
$item['conditions'] = array_values($item['conditions']);
$this->update($itemId, [
'conditions' => $item['conditions'],
]);
@@ -601,10 +598,14 @@ public function getTotal(): int|float
return Helpers::formatValue($subTotal, $this->config['format_numbers'], $this->config);
}
$conditionsForTotal->each(function (CartCondition $condition) use ($subTotal, &$total) {
$toBeCalculated = $total > 0 ? $total : $subTotal;
$index = 0;
$conditionsForTotal->each(function (CartCondition $condition) use ($subTotal, &$total, &$index) {
$toBeCalculated = ($index > 0) ? $total : $subTotal;
$total = $condition->applyCondition($toBeCalculated);
$index++;
});
return Helpers::formatValue($total, $this->config['format_numbers'], $this->config);