diff --git a/src/Cartable.php b/src/Cartable.php new file mode 100644 index 0000000..588c871 --- /dev/null +++ b/src/Cartable.php @@ -0,0 +1,10 @@ +id(); } + if (! $item instanceof Cartable) { + throw new \Exception('The item must be an instance of Cartable'); + } $cart = $query->firstOrCreate(['user_id' => $userId]); $cartItem = new CartItem([ - 'itemable_id' => $item->id, + 'itemable_id' => $item->getKey(), 'itemable_type' => $item::class, 'quantity' => $quantity, ]); @@ -74,7 +81,7 @@ public function calculatedPriceByQuantity(): int { $totalPrice = 0; foreach ($this->items()->get() as $item) { - $totalPrice += (int) $item->quantity * (int) $item->itemable->price; + $totalPrice += (int) $item->quantity * (int) $item->itemable->getPrice(); } return $totalPrice;