Skip to content

Commit 27ba394

Browse files
committed
Merge branch 'release/3.0.5'
2 parents 28037a8 + a008803 commit 27ba394

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/Storage/EloquentStorage.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace Weble\LaravelEcommerce\Storage;
44

55
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
67
use Illuminate\Database\Eloquent\ModelNotFoundException;
78
use Illuminate\Support\Collection;
9+
use Weble\LaravelEcommerce\Cart\CartItem;
810

911
class 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

tests/Cart/CartTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff 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
],

0 commit comments

Comments
 (0)