From 89c0c0e2725ea19753ad71aba65b3a6e445de25c Mon Sep 17 00:00:00 2001 From: himu3355 Date: Fri, 21 May 2021 19:38:39 +0530 Subject: [PATCH] changed getTotal() method with condition. old one is conditions value counting sequentially it geting wrong answer while adding two or more percentage value of conditions. So I first applied the value of the condition in subtotal and took the sum of the conditions. and added with subTotal. --- src/Darryldecode/Cart/Cart.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/Darryldecode/Cart/Cart.php b/src/Darryldecode/Cart/Cart.php index 503dce7..834d7f7 100644 --- a/src/Darryldecode/Cart/Cart.php +++ b/src/Darryldecode/Cart/Cart.php @@ -620,9 +620,7 @@ public function getTotal() { $subTotal = $this->getSubTotal(false); - $newTotal = 0.00; - - $process = 0; + $conditionTotal = 0.00; $conditions = $this ->getConditions() @@ -636,15 +634,11 @@ public function getTotal() } $conditions - ->each(function (CartCondition $cond) use ($subTotal, &$newTotal, &$process) { - $toBeCalculated = ($process > 0) ? $newTotal : $subTotal; - - $newTotal = $cond->applyCondition($toBeCalculated); - - $process++; + ->each(function (CartCondition $cond) use ($subTotal, &$conditionTotal) { + $conditionTotal = $cond->applyCondition($subTotal); }); - return Helpers::formatValue($newTotal, $this->config['format_numbers'], $this->config); + return Helpers::formatValue($subTotal+$conditionTotal, $this->config['format_numbers'], $this->config); } /**