7
7
8
8
namespace Magento \SendFriendGraphQl \Model \Resolver ;
9
9
10
- use Magento \Authorization \Model \UserContextInterface ;
11
10
use Magento \Framework \GraphQl \Config \Element \Field ;
12
11
use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
13
12
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
14
13
use Magento \Framework \GraphQl \Query \ResolverInterface ;
15
14
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
15
+ use Magento \GraphQl \Model \Query \ContextInterface ;
16
16
use Magento \SendFriend \Helper \Data as SendFriendHelper ;
17
17
use Magento \SendFriendGraphQl \Model \SendFriend \SendEmail ;
18
18
@@ -48,10 +48,10 @@ public function __construct(
48
48
*/
49
49
public function resolve (Field $ field , $ context , ResolveInfo $ info , array $ value = null , array $ args = null )
50
50
{
51
- $ userId = $ context-> getUserId ();
52
- $ userType = $ context -> getUserType ();
53
-
54
- if (! $ this -> sendFriendHelper -> isAllowForGuest () && $ this -> isUserGuest ( $ userId , $ userType ) ) {
51
+ /** @var ContextInterface $context */
52
+ if (! $ this -> sendFriendHelper -> isAllowForGuest ()
53
+ && false === $ context -> getExtensionAttributes ()-> getIsCustomer ()
54
+ ) {
55
55
throw new GraphQlAuthorizationException (__ ('The current customer isn \'t authorized. ' ));
56
56
}
57
57
@@ -63,7 +63,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
63
63
$ senderData ,
64
64
$ recipientsData
65
65
);
66
-
67
66
return array_merge ($ senderData , $ recipientsData );
68
67
}
69
68
@@ -123,19 +122,4 @@ private function extractSenderData(array $args): array
123
122
],
124
123
];
125
124
}
126
-
127
- /**
128
- * Checking if current customer is guest
129
- *
130
- * @param int|null $customerId
131
- * @param int|null $customerType
132
- * @return bool
133
- */
134
- private function isUserGuest (?int $ customerId , ?int $ customerType ): bool
135
- {
136
- if (null === $ customerId || null === $ customerType ) {
137
- return true ;
138
- }
139
- return 0 === (int )$ customerId || (int )$ customerType === UserContextInterface::USER_TYPE_GUEST ;
140
- }
141
125
}
0 commit comments