Check for valid session object before calling get_customer_id in Cart Route (#52410)
* Check for valid session object before calling get_customer_id in Cart Route * Add changefile(s) from automation for the following project(s): woocommerce * Harden get_cart_token function to make sure the cart is loaded before we access the session --------- Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
parent
8716d97996
commit
8fa2797a6f
|
@ -0,0 +1,4 @@
|
||||||
|
Significance: patch
|
||||||
|
Type: fix
|
||||||
|
|
||||||
|
Make sure session exists before calling its functions in the Cart StoreApi route
|
|
@ -188,6 +188,13 @@ abstract class AbstractCartRoute extends AbstractRoute {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function get_cart_token() {
|
protected function get_cart_token() {
|
||||||
|
// Ensure cart is loaded.
|
||||||
|
$this->cart_controller->load_cart();
|
||||||
|
|
||||||
|
if ( ! wc()->session ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return JsonWebToken::create(
|
return JsonWebToken::create(
|
||||||
[
|
[
|
||||||
'user_id' => wc()->session->get_customer_id(),
|
'user_id' => wc()->session->get_customer_id(),
|
||||||
|
|
Loading…
Reference in New Issue