Undefined index: cart in class-cocart-session-handler.php on line 790
AlceoMazza opened this issue · comments
Describe the bug
The following lines get appended to the body of a response made to endpoints of "wc/v3", "wp/v2" namespaces
<br />
<b>Notice</b>: Undefined index: cart in <b>/[PATH_TO_WORDPRESS_INSTALLATION]/wp-content/plugins/cart-rest-api-for-woocommerce/includes/class-cocart-session-handler.php</b> on line <b>790</b><br />
Prerequisites
- I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- The issue still exists against the latest
master
branch of CoCart on GitHub (this is not the same version as on WordPress.org!) - I have attempted to find the simplest possible steps to reproduce the issue.
- I have included a failing test as a pull request (Optional)
- I have installed the requirements to run this plugin.
Steps to reproduce the issue
- Have debug mode enabled
- Had a 2.x version of CoCart
- Updated to CoCart 3.x
- The error started to appear and broke the body of some REST responses
Isolating the problem
- This bug happens with only WooCommerce and CoCart plugin are active.
- This bug happens with a default WordPress theme active.
- This bug happens with the WordPress theme Storefront active.
- This bug happens with the latest release of WooCommerce active.
- This bug happens only when I authenticate as a customer.
- This bug happens only when I authenticate as administrator.
- I can reproduce this bug consistently using the steps above.
WordPress Environment
WordPress version: 5.8.1
WooCommerce: 5.8.0
CoCart version: 3.0.12 (the bug still persists in 3.1.0-rc.4)
PHP Version 7.3.31
Additional context
I have a WordPress instance where I installed CoCart 2.x a few months ago. I was testing an mobile app that needed the make requests to "cocart/v1", "wp/v2" and "wc/v3" and all the responses were fine. Then I updated to 3.x after it was released and all the responses made to "wp/v2" and "wc/v3" started to came with the lines specified above appended at the bottom of the response (with also the wp_cocart_session, but it's not needed when making requests to these namespaces). The bug still persists in version 3.1.0-rc.4 (line 804 of the file).
I've tried in WooCommerce > Status > Tools to:
- Clear cart sessions
- Clear expired carts
- Update CoCart Database
- Verify CoCart base database tables
The notice was still appearing.
Also I later used CoCart in other WP instances, with the first installation being a 3.x for all and the problem did not appear (all have debug mode enabled). I've also tried to reduce the installed plugins of the compromised version to a subset of the working instances installed plugins, but still the notice was appearing.
Only difference: deleteing Yoast SEO plugin made the notice disappear from some endpoint of "wp/v2" and "wc/v3", but it's till present on others of the same namespaces
The notice persists in version 3.0.13 too (line 813).
Hi @AlceoMazza
Thank you for the report. Just to clarify, it's only on any endpoint starting with wp/v2
or wc/v3
and none of CoCart endpoints while having Yoast SEO active?
Hi @seb86
Yes, it's only related to endpoints in wp/v2
or wc/v3
, in endpoints starting with cocart/v1
and cocart/v2
the notice never appeared.
With Yoast SEO enabled the notice appeared as far as I know on all wp/v2
and wc/v3
endpoints, after I uninstalled it the noticed disappeared in some endpoints (i.e. wc/v3/products/categories
) but it's still present in others (i.e. wc/v3/products
)
@AlceoMazza What an odd bug. OK thank you again. I will get that fixed asap.
Great! Thanks @seb86
@AlceoMazza I have not been able to replicate the issue on my end on any REST API request even with Yoast SEO installed. However, I have made an adjustment that I hope works and would like you to test for me. If you no longer get the issue I will push the update.
You can download the working patch from branch issue-273
Thank you.
Thank you very much @seb86, the patch solves the issue, now I'm able to make requests to wp/v2
and wc/v3
endpoints without having the response body broken in debug mode.
That's great to hear @AlceoMazza and everything is still working fine with CoCart?
@seb86 Yes, the CoCart endpoints are still working fine