Update Cart.php

This commit is contained in:
Patrick
2022-02-05 20:18:17 +01:00
committed by GitHub
parent 08f4256242
commit b0de33e35c

View File

@@ -149,10 +149,19 @@ class Cart
} }
/* Also allow passing multiple definitions at the same time, simply call same method and collec return value */ /* Also allow passing multiple definitions at the same time, simply call same method and collec return value */
else if (is_iterable($id)) { else if (is_iterable($id)) {
/* Check if this iterable contains instances */
if (is_array(head($item)) || head($item) instanceof Buyable) {
return array_map(function ($item) { return array_map(function ($item) {
return $this->add($item); return $this->add($item);
}, $id); }, $id);
} }
/* Treat the array itself as an instance */
else {
$cartItem = CartItem::fromArray($id);
return $this->addCartItem($cartItem);
}
}
/* Due to PHP8 union types this should never happen */ /* Due to PHP8 union types this should never happen */
else { else {
throw new InvalidArgumentException('$id must be of type int|string|Buyable|Iterable'); throw new InvalidArgumentException('$id must be of type int|string|Buyable|Iterable');