Skip to content

Commit 8fd5ee5

Browse files
authored
Bug fix
Hey, This is my first time to contribute to this amazing package. Thank you for making this piece of ART! I encountered a weird bug after checking laravel log file. after digging deeper. I finally succeed to reproduce it. ``` [2020-05-05 18:14:54] local.ERROR: Argument 1 passed to Darryldecode\Cart\Cart::Darryldecode\Cart\{closure}() must be an instance of Darryldecode\Cart\ItemCollection, array given, called in /Users/norredine/code/test-project/vendor/laravel/framework/src/Illuminate/Support/Traits/EnumeratesValues.php on line 424 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to Darryldecode\\Cart\\Cart::Darryldecode\\Cart\\{closure}() must be an instance of Darryldecode\\Cart\\ItemCollection, array given, called in /Users/norredine/code/test-project/vendor/laravel/framework/src/Illuminate/Support/Traits/EnumeratesValues.php on line 424 at /Users/norredine/code/test-project/vendor/darryldecode/cart/src/Darryldecode/Cart/Cart.php:581) [stacktrace] ``` ### Steps to reproduce, Delete an item from cart, then update quantity for the same cart item id. Thank you.
1 parent ae299df commit 8fd5ee5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Darryldecode/Cart/Cart.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,9 @@ public function getTotalQuantity()
672672
*/
673673
public function getContent()
674674
{
675-
return (new CartCollection($this->session->get($this->sessionKeyCartItems)));
675+
return (new CartCollection($this->session->get($this->sessionKeyCartItems)))->reject(function($item) {
676+
return ! ($item instanceof ItemCollection);
677+
});
676678
}
677679

678680
/**
@@ -682,9 +684,7 @@ public function getContent()
682684
*/
683685
public function isEmpty()
684686
{
685-
$cart = new CartCollection($this->session->get($this->sessionKeyCartItems));
686-
687-
return $cart->isEmpty();
687+
return $this->getContent()->isEmpty();
688688
}
689689

690690
/**

0 commit comments

Comments
 (0)