File tree Expand file tree Collapse file tree 1 file changed +6
-18
lines changed
Expand file tree Collapse file tree 1 file changed +6
-18
lines changed Original file line number Diff line number Diff line change 55namespace Cone \Bazar \Console \Commands ;
66
77use Cone \Bazar \Models \Cart ;
8- use Cone \Bazar \Models \Item ;
9- use Cone \Bazar \Models \Shipping ;
108use Illuminate \Console \Command ;
119
1210class 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 }
You can’t perform that action at this time.
0 commit comments