mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
chore: bump to v2.0.0 with PHP 8.3+ support and invalid item cleanup
This commit is contained in:
@@ -165,9 +165,31 @@ public function add(
|
||||
|
||||
$this->currentItemId = $id;
|
||||
|
||||
// clean up any incomplete items
|
||||
$this->removeInvalidItems();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove any incomplete items
|
||||
*/
|
||||
public function removeInvalidItems(): bool
|
||||
{
|
||||
$carts = $this->getContent();
|
||||
|
||||
foreach ($carts as $index => $cart) {
|
||||
|
||||
if (! (isset($cart['id'], $cart['name'], $cart['quantity']))) {
|
||||
|
||||
// remove item
|
||||
$this->remove($index);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a cart item with whatever data is passed in
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user