From f2ae1331f89192679b881af0566c196d67948117 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 9 Feb 2022 00:08:25 +0100 Subject: [PATCH] Update CartModel.php --- src/Models/CartModel.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Models/CartModel.php b/src/Models/CartModel.php index ce393f6..600e777 100644 --- a/src/Models/CartModel.php +++ b/src/Models/CartModel.php @@ -134,7 +134,15 @@ class CartModel extends Model public function weight(): Attribute { return new Attribute( - get: fn () => $this->qty * $this->weight, + get: fn (): int => { + $sum = 0; + + foreach (this->items as $item) { + $sum += $this->qty * $this->weight; + } + + return $sum; + }, ); } }