From 6dc29116532cdd93a1576217805ec07b36e6678f Mon Sep 17 00:00:00 2001 From: r14ull Date: Wed, 16 Oct 2024 19:28:26 +0100 Subject: [PATCH 1/4] Update ItemCollection.php allow conditions to calculate on line total rather than on a single item --- src/Darryldecode/Cart/ItemCollection.php | 29 +++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Darryldecode/Cart/ItemCollection.php b/src/Darryldecode/Cart/ItemCollection.php index a71503f..9ee2265 100644 --- a/src/Darryldecode/Cart/ItemCollection.php +++ b/src/Darryldecode/Cart/ItemCollection.php @@ -121,6 +121,33 @@ public function getPriceWithConditions($formatted = true) return Helpers::formatValue($originalPrice, $formatted, $this->config); } + + public function getPriceTotalWithConditions($formatted = true) + { + $originalTotalPrice = $this->price * $this->quantity; + $newPrice = 0.00; + $processed = 0; + if ($this->hasConditions()) { + + if (is_array($this->conditions)) { + foreach ($this->conditions as $condition) { + ($processed > 0) ? $toBeCalculated = $discount : $toBeCalculated = $this->price; + + $discount = $condition->getCalculatedValue($toBeCalculated); + + $newTotal = $originalTotalPrice - ($discount * $this->quantity); + + $processed++; + } + } else { + $discount = $this['conditions']->getCalculatedValue($this->price) * $this->quantity; + $newTotal = $originalTotalPrice - $discount; + } + return Helpers::formatValue($newTotal, $formatted, $this->config); + } + return Helpers::formatValue($originalTotalPrice, $formatted, $this->config); + } + /** * get the sum of price in which conditions are already applied * @param bool $formatted @@ -128,6 +155,6 @@ public function getPriceWithConditions($formatted = true) */ public function getPriceSumWithConditions($formatted = true) { - return Helpers::formatValue($this->getPriceWithConditions(false) * $this->quantity, $formatted, $this->config); + return Helpers::formatValue($this->getPriceTotalWithConditions(false), $formatted, $this->config); } } From 4b9d143b6000719951300acd26a036fef22633a1 Mon Sep 17 00:00:00 2001 From: r14ull Date: Wed, 16 Oct 2024 19:53:26 +0100 Subject: [PATCH 2/4] Update ItemCollection.php --- src/Darryldecode/Cart/ItemCollection.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Darryldecode/Cart/ItemCollection.php b/src/Darryldecode/Cart/ItemCollection.php index 9ee2265..c1d3c02 100644 --- a/src/Darryldecode/Cart/ItemCollection.php +++ b/src/Darryldecode/Cart/ItemCollection.php @@ -125,20 +125,18 @@ public function getPriceWithConditions($formatted = true) public function getPriceTotalWithConditions($formatted = true) { $originalTotalPrice = $this->price * $this->quantity; + $originalPrice = $this->price; $newPrice = 0.00; $processed = 0; if ($this->hasConditions()) { if (is_array($this->conditions)) { - foreach ($this->conditions as $condition) { - ($processed > 0) ? $toBeCalculated = $discount : $toBeCalculated = $this->price; - - $discount = $condition->getCalculatedValue($toBeCalculated); - - $newTotal = $originalTotalPrice - ($discount * $this->quantity); - - $processed++; - } + $discount = 0; + foreach ($this->conditions as $condition) { + ($processed > 0) ? $toBeCalculated = ($originalPrice - $discount) : $toBeCalculated = $originalPrice; + $discount = $discount + $condition->getCalculatedValue($toBeCalculated); + } + $newTotal = $originalTotalPrice - ($discount * $this->quantity); } else { $discount = $this['conditions']->getCalculatedValue($this->price) * $this->quantity; $newTotal = $originalTotalPrice - $discount; From 8dfca92874ba9ce265a3b0811a36af991578836d Mon Sep 17 00:00:00 2001 From: r14ull Date: Fri, 2 May 2025 20:59:57 +0100 Subject: [PATCH 3/4] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index bd20160..f9ae4bb 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,9 @@ ], "require": { "php": ">=7.3", - "illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", - "illuminate/validation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0", - "illuminate/translation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0" + "illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/validation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0", + "illuminate/translation": "5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0" }, "require-dev": { "mockery/mockery": "^1.4.2", From e17e839c67fda0588046dc6beff66ba6d6a355df Mon Sep 17 00:00:00 2001 From: r14ull Date: Fri, 2 May 2025 21:36:39 +0100 Subject: [PATCH 4/4] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f9ae4bb..2d2b468 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "saleem189/cart", + "name": "darryldecode/cart", "description": "Laravel 5 Shopping cart", "keywords": ["laravel", "shopping cart", "cart"], "license": "MIT",