File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 33namespace Weble \LaravelEcommerce \Storage ;
44
55use Illuminate \Database \Eloquent \Builder ;
6+ use Illuminate \Database \Eloquent \Model ;
67use Illuminate \Database \Eloquent \ModelNotFoundException ;
78use Illuminate \Support \Collection ;
9+ use Weble \LaravelEcommerce \Cart \CartItem ;
810
911class EloquentStorage implements StorageInterface
1012{
@@ -73,8 +75,10 @@ public function get(string $key, $default = null)
7375 return $ default ;
7476 }
7577
76- return $ items ->map (function ($ model ) {
77- return $ model ->toCartValue ();
78+ return $ items ->mapWithKeys (function (Model |StoresEcommerceData $ model ) {
79+ /** @var CartItem $cartItem */
80+ $ cartItem = $ model ->toCartValue ();
81+ return [$ cartItem ->getId () => $ cartItem ];
7882 });
7983 }
8084
Original file line number Diff line number Diff line change @@ -99,6 +99,23 @@ public function can_add_to_cart($driver)
9999 $ this ->assertEquals ($ cartItem , $ retrievedCartItem );
100100 }
101101
102+ /**
103+ * @test
104+ * @dataProvider driversProvider
105+ */
106+ public function can_check_if_item_is_in_cart ($ driver )
107+ {
108+ $ this ->setCartStorageDriver ($ driver );
109+
110+ $ product = ProductFactory::new (['price ' => money (100 )])->create ();
111+
112+ /** @var Cart $cart */
113+ $ cart = app ('ecommerce.cart ' );
114+ $ cartItem = $ cart ->add ($ product , 1 );
115+
116+ $ this ->assertTrue ($ cart ->has ($ cartItem ->getId ()));
117+ }
118+
102119 /**
103120 * @test
104121 * @dataProvider driversProvider
@@ -404,15 +421,15 @@ public function can_add_discount_to_cart_storing_in_db()
404421 public function driversProvider ()
405422 {
406423 return [
407- [
424+ ' session ' => [
408425 'session ' ,
409426 SessionStorage::class,
410427 ],
411- [
428+ ' cache ' => [
412429 'cache ' ,
413430 CacheStorage::class,
414431 ],
415- [
432+ ' eloquent ' => [
416433 'eloquent ' ,
417434 EloquentStorage::class,
418435 ],
You can’t perform that action at this time.
0 commit comments