Update CartModel.php

This commit is contained in:
Patrick
2022-02-09 00:08:25 +01:00
committed by GitHub
parent 185bd8b62b
commit f2ae1331f8

View File

@@ -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;
},
);
}
}