Not able to get Cart items
-
Hi i am trying to get the cart data but i m not able to get it
/api/checkout/cart Api that i used response code is 200
{"data":null} response is null -
Hi @Akanrat,
In Bagisto, Cart handled via session and the Laravel session is checked on the basis of cookies.
Laravel is not able to see your cookies that's why every request is getting a new cart.
-
@devansh-webkul how we can make cart on the basis of user such as token or customer id
-
Authenticated user cart always linked to
customer_id
. You can easily grab that. -
GET http(s)://example.com/api/checkout/cart this api is used for getiing cart who are logged in but where to send customer_id in this ??
headers:
Accept: application/json
Authorization: Bearer token-string -
You don't need to send any customer id, as the cart is session-based once the user is authenticated cart is merged and the user id is set to the current customer id once logged in.
You just need to grab the cookies once the cart is created and then send the cookies in each reqest.
If you check the Postman, the postman automatically sends this but once it is in the application you need to store somewhere and send it.
-
If we are getting the data from the help cookies how will i maintain the cart data in different platform for eg i have added 2 shirts in cart from mobile app can i will be able to see these item in web also ???
-
Hi @Akanrat,
If the user is authenticated then yes it will be the same. Because for authenticated user cart is fetched from the database.
I think you are getting confused, I am just sharing a thread that will help you,
Actually, this is a cross-domain, you need to send the cookies so that session can be tracked. I am sharing with you a thread that can help you just try to send cookies in ajax request and it will work.
https://stackoverflow.com/questions/29417518/how-can-set-cookie-with-ajax-jquery/29417575#29417575
https://symfonycasts.com/screencast/reactjs/api-authentication