Try generating a cart key without “-” in between.
Still no success. Calling it now like this: https://websitename.com/wp-json/cocart/v2/cart/?cart_key=0dcdef20a5e011ecb2d4ab02f7dd098c
Without the “-“. But I still receive an empty array. Any more suggestions?
I tried it also with https://websitename.com/wp-json/cocart/v2/cart/?cart_key=12345 and https://websitename.com/wp-json/cocart/v2/cart/?cart_key=abcdefg
Also not working. I create the cart by just calling the GET cart endpoint. Isn’t that correct? Or do I need to call an “Make Cart” endpoint?
-
This reply was modified 2 months, 1 week ago by
julianblauw.
-
This reply was modified 2 months, 1 week ago by
julianblauw.
A cart is only created in session once the first item is added to the cart.
Did you add a product to the cart first before using a cart key?
A cart key will be provided for you in the response and via the response headers X-COCART-API
Aah okay. I tried that now. I now called the endpoint to add an item to the cart first: https://websitename.com/wp-json/cocart/v2/cart/add-item. I received a cart key in the response generated by CoCart. Looking like this: ‘fb85933850fb2097c190e21b52bb05e9’.
Then I call the following endpoint: https://websitename.com/wp-json/cocart/v2/cart/?cart_key=fb85933850fb2097c190e21b52bb05e9 but items is still empty.
Here is an image of the postman call to get the cart items and to add an item to the cart: https://imgur.com/a/rDZlyB2
I am not sure what you mean with “X-COCART-API”.
Can you check that a CoCart table exists in your database because it’s never failed to return on the next request unless it does not understand the cart key formatting?
I checked the database. The table CoCart exists and it contains 1 row. But this is the cart key of a logged-in user with JWT. Note: The cart does work with JWT.
The CoCart table does not have a row with the (guest) cart key. Why is that?
If you are authenticating then CoCart will assume that the user you logged in as is the customer. Anything the guest cart had will merge into the authenticated cart and will destroy the guest cart after.
Hmm ok that is pretty cool, but if I am logged out. And I add an item to the cart as a guest, then call the endpoint to receive the cart, the cart items still remain empty.
Like I mentioned before, this is what I tried to do:
1. Call endpoint to add an item (no JWT): https://websitename.com/wp-json/cocart/v2/cart/add-item. (CoCart creates cart_key and returned it in response)
2. Call endpoint to get the cart (no JWT): https://websitename.com/wp-json/cocart/v2/cart/?cart_key=fb85933850fb2097c190e21b52bb05e9. Cart_key is added in the parameters.
The response contains an item array. An item array that is empty.
I’ve tested several times with the current release and everything is doing as it should so there must be something block it’s ability to save the cart in session.
Please enable debug mode and try again. If there are any errors logged related to CoCart please let me know.
I updated the plugin and CoCart Database on the WordPress website and now it works! Thank you for helping me out. But my version of CoCart was not that old. I updated the plugin a few weeks ago. Were these features recently built?
Thanks again!
No the feature is not recent. It’s possible the plugin failed to update properly or you were not prompted to update the database.
Glad it is now working for you.
Marking as resolved.
Okay, that makes sense. Yea I am happy that it is working now. Thanks for your help!