5
5
namespace App \GraphQL \Souk \Mutations \Cart ;
6
6
7
7
use Illuminate \Support \Facades \App ;
8
+ use Joelwmale \Cart \CartCondition ;
8
9
use Kanvas \Apps \Models \Apps ;
10
+ use Kanvas \Companies \Models \CompaniesBranches ;
11
+ use Kanvas \Enums \AppEnums ;
9
12
use Kanvas \Exceptions \ModelNotFoundException ;
10
13
use Kanvas \Souk \Cart \Actions \AddToCartAction ;
11
14
use Kanvas \Souk \Cart \Services \CartService ;
12
- use Wearepixel \Cart \CartCondition ;
13
15
14
16
class CartManagementMutation
15
17
{
16
18
public function add (mixed $ root , array $ request ): array
17
19
{
18
20
$ user = auth ()->user ();
19
- $ company = $ user ->getCurrentCompany ();
21
+ $ company = $ user ? $ user ->getCurrentCompany () : app (CompaniesBranches::class)->company ;
22
+
23
+ if (! $ company ) {
24
+ throw new ModelNotFoundException ('No company found ' );
25
+ }
26
+
20
27
$ currentUserCompany = $ company ;
21
28
$ app = app (Apps::class);
22
- $ cart = app ('cart ' )->session ($ user ->getId ());
23
-
24
- $ addToCartAction = new AddToCartAction ($ app , $ user , $ currentUserCompany );
29
+ $ cart = app ('cart ' )->session (app (AppEnums::KANVAS_IDENTIFIER ->getValue ()));
30
+ $ addToCartAction = new AddToCartAction ($ app , $ currentUserCompany , $ user );
25
31
26
32
return $ addToCartAction ->execute ($ cart , $ request ['items ' ]);
27
33
}
28
34
29
35
public function update (mixed $ root , array $ request ): array
30
36
{
31
- $ user = auth ()->user ();
32
- $ cart = app ('cart ' )->session ($ user ->getId ());
37
+ $ cart = app ('cart ' )->session (app (AppEnums::KANVAS_IDENTIFIER ->getValue ()));
33
38
34
39
if (! $ cart ->has ($ request ['variant_id ' ])) {
35
40
return [];
@@ -45,7 +50,7 @@ public function update(mixed $root, array $request): array
45
50
public function remove (mixed $ root , array $ request ): array
46
51
{
47
52
$ user = auth ()->user ();
48
- $ cart = app ('cart ' )->session ($ user -> getId ( ));
53
+ $ cart = app ('cart ' )->session (app (AppEnums:: KANVAS_IDENTIFIER -> getValue () ));
49
54
50
55
$ cart ->remove ($ request ['variant_id ' ]);
51
56
@@ -55,7 +60,7 @@ public function remove(mixed $root, array $request): array
55
60
public function discountCodesUpdate (mixed $ root , array $ request ): array
56
61
{
57
62
$ user = auth ()->user ();
58
- $ cart = app ('cart ' )->session ($ user -> getId ( ));
63
+ $ cart = app ('cart ' )->session (app (AppEnums:: KANVAS_IDENTIFIER -> getValue () ));
59
64
$ app = app (Apps::class);
60
65
61
66
/**
@@ -92,7 +97,7 @@ public function discountCodesUpdate(mixed $root, array $request): array
92
97
public function clear (mixed $ root , array $ request ): bool
93
98
{
94
99
$ user = auth ()->user ();
95
- $ cart = app ('cart ' )->session ($ user -> getId ( ));
100
+ $ cart = app ('cart ' )->session (app (AppEnums:: KANVAS_IDENTIFIER -> getValue () ));
96
101
$ cart ->clearAllConditions ();
97
102
98
103
return $ cart ->clear ();
0 commit comments