Skip to content

Commit 0f8c93c

Browse files
committed
add null cart driver
1 parent 19397d0 commit 0f8c93c

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

config/bazar.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
'expiration' => 4320,
4141
],
4242
'session' => [],
43+
'null' => [],
4344
],
4445
],
4546

src/Cart/Driver.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function getModel(): Cart
8585
$cart->syncItems();
8686
$cart->shipping->calculateFee();
8787
$cart->shipping->calculateTaxes();
88-
$cart->getModel()->calculateDiscount();
88+
$cart->calculateTax();
89+
$cart->calculateDiscount();
8990
}
9091
});
9192
}
@@ -248,12 +249,22 @@ public function empty(): void
248249
$this->getModel()->setRelation('items', $this->getModel()->items()->getRelated()->newCollection());
249250

250251
$this->getShipping()->update(['fee' => 0]);
251-
$this->getShipping()->taxes()->delete();
252+
$this->getShipping()->taxes()->detach();
252253
$this->getShipping()->discounts()->detach();
253254

254255
$this->getModel()->calculateDiscount();
255256
}
256257

258+
/**
259+
* Delete the cart.
260+
*/
261+
public function destroy(): void
262+
{
263+
$this->getModel()->items->each->delete();
264+
$this->getShipping()->delete();
265+
$this->getModel()->delete();
266+
}
267+
257268
/**
258269
* Get the number of the cart items.
259270
*/

src/Cart/Manager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,14 @@ public function createSessionDriver(): SessionDriver
3636
$this->config->get('bazar.cart.drivers.session', [])
3737
);
3838
}
39+
40+
/**
41+
* Create the null driver.
42+
*/
43+
public function createNullDriver(): NullDriver
44+
{
45+
return new NullDriver(
46+
$this->config->get('bazar.cart.drivers.null', [])
47+
);
48+
}
3949
}

src/Cart/NullDriver.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cone\Bazar\Cart;
6+
7+
use Cone\Bazar\Models\Cart;
8+
use Illuminate\Http\Request;
9+
10+
class NullDriver extends Driver
11+
{
12+
/**
13+
* Resolve the cart for the current request.
14+
*/
15+
public function resolve(Request $request): Cart
16+
{
17+
return Cart::proxy()->newInstance();
18+
}
19+
}

src/Support/Facades/Cart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* @method static bool applyCoupon(string|\Cone\Bazar\Models\Coupon $coupon)
3030
* @method static void removeCoupon(string|\Cone\Bazar\Models\Coupon $coupon)
3131
* @method static \Cone\Bazar\Gateway\Response checkout(string $driver)
32+
* @method static \Cone\Bazar\Cart\Driver driver(?string $driver = null)
3233
*
3334
* @see \Cone\Bazar\Cart\Driver
3435
*/

0 commit comments

Comments
 (0)