dystcz / dystore-api

API layer for Lunar headless e-commerce package based on JSON:API
https://lunar-api-sepia.vercel.app
MIT License
27 stars 4 forks source link

Cart not assigning to user #161

Closed pox0 closed 1 month ago

pox0 commented 6 months ago

We are using laravel/sanctum. When I try to call add-to-cart endpoints. Its creating a cart and cart-lines but it didn't assign to the user. I'm calling the endpoint with authorization bearer token.

harriskhalil commented 2 months ago

did you find any solution to that?

repl6669 commented 2 months ago

Hello, I will try to reproduce it myself and will let you know.

I will add tests for this if they are missing.

repl6669 commented 2 months ago

Hey @pox0 and @harriskhalil, I added a test (https://github.com/dystcz/lunar-api/pull/173) proving that user actually gets associated with the current cart in session. https://github.com/dystcz/lunar-api/blob/d4737b61f435d1044773bb58b11744499b88d430/tests/Feature/Domain/CartLines/JsonApi/V1/CreateCartLineTest.php#L71-L114

But it only does so during the login process. So if you only send a token of already logged in User with the request, it will not work, because the \Lunar\Listeners\CartSessionAuthListener will not be triggered by the Illuminate\Auth\Events\Login event.

Can you try the following?

  1. POST to api/v1/cart-lines to create a CartLine without the user being logged in.
  2. Call your login endpoint
  3. Check if the cart is associated

Btw which version are you on? 0.8.x / 1.0.0-x ?