@@ -76,7 +76,7 @@ class GetTokenData extends AbstractExpress implements HttpGetActionInterface
76
76
private $ guestCartRepository ;
77
77
78
78
/**
79
- * @var UserContextInterface
79
+ * @var UserContextInterface|null
80
80
*/
81
81
private $ userContext ;
82
82
@@ -109,7 +109,7 @@ public function __construct(
109
109
CustomerRepository $ customerRepository ,
110
110
CartRepositoryInterface $ cartRepository ,
111
111
GuestCartRepositoryInterface $ guestCartRepository ,
112
- UserContextInterface $ userContext
112
+ UserContextInterface $ userContext = null
113
113
) {
114
114
parent ::__construct (
115
115
$ context ,
@@ -162,9 +162,32 @@ public function execute(): ResultInterface
162
162
$ responseContent ['error_message ' ] = __ ('Sorry, but something went wrong ' );
163
163
}
164
164
165
+ if (!$ responseContent ['success ' ]) {
166
+ $ this ->messageManager ->addErrorMessage ($ responseContent ['error_message ' ]);
167
+ }
168
+
165
169
return $ controllerResult ->setData ($ responseContent );
166
170
}
167
171
172
+ /**
173
+ * Prepare quote specified for checkout.
174
+ *
175
+ * @return \Magento\Quote\Api\Data\CartInterface
176
+ * @throws LocalizedException
177
+ */
178
+ private function prepareQuote ()
179
+ {
180
+ $ quoteId = $ this ->getRequest ()->getParam ('quote_id ' );
181
+ if ($ quoteId ) {
182
+ $ quote = $ this ->userContext ->getUserId ()
183
+ ? $ this ->cartRepository ->get ($ quoteId )
184
+ : $ this ->guestCartRepository ->get ($ quoteId );
185
+ if ((int )$ quote ->getCustomer ()->getId () === (int )$ this ->userContext ->getUserId ()) {
186
+ return $ quote ;
187
+ }
188
+ }
189
+ return $ this ->_getQuote ();
190
+ }
168
191
/**
169
192
* Get paypal token
170
193
*
@@ -173,7 +196,7 @@ public function execute(): ResultInterface
173
196
*/
174
197
private function getToken (): ?string
175
198
{
176
- $ quote = $ this ->_getQuote ();
199
+ $ quote = $ this ->prepareQuote ();
177
200
$ this ->_initCheckout ($ quote );
178
201
179
202
if ($ quote ->getIsMultiShipping ()) {
0 commit comments