From ae0a976785e45e53fe6a29f08e03fc0fb4331a57 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 29 Aug 2020 15:47:33 +0200 Subject: [PATCH] Prevent negative subtotal Manual merge of https://github.com/iainheng/LaravelShoppingcart/commit/33fc42dae115089221f01c2a6a27506b14f763c4 --- src/CartItem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CartItem.php b/src/CartItem.php index 0bf3a8d..675371b 100644 --- a/src/CartItem.php +++ b/src/CartItem.php @@ -412,7 +412,7 @@ class CartItem implements Arrayable, Jsonable case 'priceTotal': return round($this->priceNet * $this->qty, $decimals); case 'subtotal': - return round($this->priceTotal - $this->discountTotal, $decimals); + return max(round($this->priceTotal - $this->discountTotal, $decimals), 0); case 'priceTarget': return round(($this->priceTotal - $this->discountTotal) / $this->qty, $decimals); case 'taxTotal': @@ -435,7 +435,7 @@ class CartItem implements Arrayable, Jsonable case 'priceTotal': return round($this->price * $this->qty, $decimals); case 'subtotal': - return round($this->priceTotal - $this->discountTotal, $decimals); + return max(round($this->priceTotal - $this->discountTotal, $decimals), 0); case 'priceTarget': return round(($this->priceTotal - $this->discountTotal) / $this->qty, $decimals); case 'taxTotal':