From d4dad63481696ae88296fc48fdc6253ea395806b Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 5 Feb 2022 19:44:28 +0100 Subject: [PATCH] Update Cart.php --- src/Cart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cart.php b/src/Cart.php index 29cf5ea..b03817f 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -118,7 +118,7 @@ class Cart * * @return \Gloudemans\Shoppingcart\CartItem */ - public function add(int|string|Buyable|iterable $id, null|string|int $nameOrQty = null, null|int|array $qtyOrOptions = null, ?Money $price = null, ?int $weight = null, array $options = []): CartItem|array + public function add(int|string|Buyable|iterable $id, null|string|int $nameOrQty = null, null|int|array $qtyOrOptions = null, ?Money $price = null, ?int $weight = null, ?CartItemOptions $options = null): CartItem|array { /* Allow adding a CartItem by raw parameters */ if (is_int($id) || is_string($id)) { @@ -130,7 +130,7 @@ class Cart throw new InvalidArgumentException('$nameOrQty must be of int (quantity) or null when adding with raw parameters'); } - return $this->addCartItem(CartItem::fromAttributes($id, $nameOrQty, $price, $qtyOrOptions ?: 1, $weight, $options)); + return $this->addCartItem(CartItem::fromAttributes($id, $nameOrQty, $price, $qtyOrOptions ?: 1, $weight, $options ?: new CartItemOptions([]))); } /* Also allow passing a Buyable instance, get data from the instance rather than parameters */ else if ($id instanceof Buyable) {