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:
Alex Florisca 2024-10-29 14:54:26 +00:00 committed by GitHub
parent 8716d97996
commit 8fa2797a6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Make sure session exists before calling its functions in the Cart StoreApi route

View File

@ -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(),