11
11
use Magento \Framework \Webapi \Rest \Request as RestRequest ;
12
12
use Magento \Customer \Api \Data \CustomerInterface ;
13
13
use Magento \Customer \Api \CustomerRepositoryInterface ;
14
- use Magento \Customer \Model \Session ;
15
14
use Magento \Framework \App \ObjectManager ;
15
+ use Magento \Integration \Model \Oauth \Token ;
16
16
17
17
/**
18
18
* Update customer by id from request param
@@ -25,21 +25,21 @@ class UpdateCustomer
25
25
private $ request ;
26
26
27
27
/**
28
- * @var Session
28
+ * @var Token
29
29
*/
30
- private $ session ;
30
+ private $ token ;
31
31
32
32
/**
33
33
* @param RestRequest $request
34
- * @param Session |null $session
34
+ * @param Token |null $token
35
35
*/
36
36
public function __construct (
37
37
RestRequest $ request ,
38
- Session $ session = null
38
+ Token $ token = null
39
39
) {
40
40
$ this ->request = $ request ;
41
- $ this ->session = $ session ?: ObjectManager::getInstance ()
42
- ->get (Session ::class);
41
+ $ this ->token = $ token ?: ObjectManager::getInstance ()
42
+ ->get (Token ::class);
43
43
}
44
44
45
45
/**
@@ -56,9 +56,17 @@ public function beforeSave(
56
56
?string $ passwordHash = null
57
57
): array {
58
58
$ customerId = $ this ->request ->getParam ('customerId ' );
59
-
60
- if ($ customerId && $ customerId === $ this ->session ->getData ('customer_id ' )) {
61
- $ customer = $ this ->getUpdatedCustomer ($ customerRepository ->getById ($ customerId ), $ customer );
59
+ $ cookie = $ this ->request ->getHeader ('cookie ' );
60
+ $ headerToken = $ this ->request ->getHeader ('Authorization ' );
61
+ if ($ customerId && !str_contains ($ cookie , 'PHPSESSID ' )) {
62
+ if (str_contains ($ headerToken , 'Bearer ' )) {
63
+ $ token = "Bearer " . $ this ->token ->loadByCustomerId ($ customerId )->getData ('token ' );
64
+ if ($ headerToken === $ token ) {
65
+ $ customer = $ this ->getUpdatedCustomer ($ customerRepository ->getById ($ customerId ), $ customer );
66
+ }
67
+ } else {
68
+ $ customer = $ this ->getUpdatedCustomer ($ customerRepository ->getById ($ customerId ), $ customer );
69
+ }
62
70
}
63
71
64
72
return [$ customer , $ passwordHash ];
0 commit comments