Skip to content

Commit ef92ae0

Browse files
committed
wip
1 parent 389afb4 commit ef92ae0

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/Console/Commands/ClearCarts.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Cone\Bazar\Console\Commands;
66

77
use Cone\Bazar\Models\Cart;
8-
use Cone\Bazar\Models\Item;
9-
use Cone\Bazar\Models\Shipping;
108
use Illuminate\Console\Command;
119

1210
class ClearCarts extends Command
@@ -31,25 +29,15 @@ class ClearCarts extends Command
3129
public function handle(): void
3230
{
3331
if ($this->option('all')) {
34-
Cart::proxy()->newQuery()->truncate();
35-
Item::proxy()->newQuery()->where('checkoutable_type', Cart::getProxiedClass())->delete();
36-
Shipping::proxy()->newQuery()->where('shippable_type', Cart::getProxiedClass())->delete();
32+
Cart::proxy()->newQuery()->cursor()->each(static function (Cart $cart): void {
33+
$cart->delete();
34+
});
3735

3836
$this->info('All carts have been deleted.');
3937
} else {
40-
Item::proxy()
41-
->newQuery()
42-
->where('checkoutable_type', Cart::getProxiedClass())
43-
->whereIn('checkoutable_id', Cart::proxy()->newQuery()->expired()->select('id'))
44-
->delete();
45-
46-
Shipping::proxy()
47-
->newQuery()
48-
->where('shippable_type', Cart::getProxiedClass())
49-
->whereIn('shippable_id', Cart::proxy()->newQuery()->expired()->select('id'))
50-
->delete();
51-
52-
Cart::proxy()->newQuery()->expired()->delete();
38+
Cart::proxy()->newQuery()->expired()->cursor()->each(static function (Cart $cart): void {
39+
$cart->delete();
40+
});
5341

5442
$this->info('Expired carts have been deleted.');
5543
}

0 commit comments

Comments
 (0)