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,9 +149,18 @@ 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)) {
return array_map(function ($item) { /* Check if this iterable contains instances */
return $this->add($item); if (is_array(head($item)) || head($item) instanceof Buyable) {
}, $id); return array_map(function ($item) {
return $this->add($item);
}, $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 {