Skip to content

Commit 2695072

Browse files
committed
Filter conditions with target subtotal before checking if we have conditions
1 parent c79bd52 commit 2695072

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Darryldecode/Cart/Cart.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -537,22 +537,26 @@ public function getTotal()
537537

538538
$process = 0;
539539

540-
$conditions = $this->getConditions();
540+
$conditions = $this
541+
->getConditions()
542+
->filter(function ($cond) {
543+
return $cond->getTarget() === 'subtotal';
544+
});
541545

542546
// if no conditions were added, just return the sub total
543547
if (!$conditions->count()) {
544548
return Helpers::formatValue($subTotal, $this->config['format_numbers'], $this->config);
545549
}
546550

547-
$conditions->each(function ($cond) use ($subTotal, &$newTotal, &$process) {
548-
if ($cond->getTarget() === 'subtotal') {
549-
($process > 0) ? $toBeCalculated = $newTotal : $toBeCalculated = $subTotal;
551+
$conditions
552+
->each(function ($cond) use ($subTotal, &$newTotal, &$process) {
553+
$toBeCalculated = ($process > 0) ? $newTotal : $subTotal;
550554

551555
$newTotal = $cond->applyCondition($toBeCalculated);
552556

553557
$process++;
554-
}
555-
});
558+
559+
});
556560

557561
return Helpers::formatValue($newTotal, $this->config['format_numbers'], $this->config);
558562
}

0 commit comments

Comments
 (0)