Answers.Body: <p>UPD 2: Spending more hours gave me the solution:</p>
  <p>It seems like Ajax generates a new sessionId with each call, so it's impossible to preserve cart along with session Id in that case. As workaround I was trying to pass session id cookie manually, but it was rejected by Axios.</p>
  <p>What I have found is that you can actually call <code>action=commerce/cart/get-cart&amp;note=from+ajax</code> as POST request with passing the following body:</p>
  <pre><code>{
      &quot;orderNumber&quot;: &quot;{{ number of a cart }}&quot;
  }
  </code></pre>
  <p>So it can be used to load the cart you actually need. Therefore there is no need to use <code>?action=commerce/cart/load-cart&amp;note=from+ajax&amp;number={number}</code> cause it works only with sessions.</p>
  <p>The only thing you need is to store cart number in your localStorage or store to pass it as body parameter</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-11T12:46:29.990Z
Answers.LastActivityDate: 2020-12-11T12:46:29.990Z
Answers.UserDisplayName: Alex89
Answers.Body: <p>UPD: after some hours of research I found the solution in this topic:</p>
  <p><a href="https://craftcms.stackexchange.com/questions/35791/cors-preflight-check-failing-for-ajax-login-form-on-different-domain">CORS preflight check failing for AJAX login form on different domain</a></p>
  <p>Also I had to pass the <code>orderNumber</code> parameter with the value of cart number in payload.</p>
  <p>However I have a different issue now. First I call <code>?action=commerce/cart/load-cart&amp;note=from+ajax&amp;number={number}</code> to load my stored card into the session. Then I call <code>action=commerce/cart/get-cart&amp;note=from+ajax</code> to get the content of the cart I loaded in step one, but it returns me a new empty cart. I suppose there is something to deal with the CraftSessionId in headers, am I right?</p>
  <p><a href="https://i.sstatic.net/vyUsB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vyUsB.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.sstatic.net/TXCJi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TXCJi.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-12-10T20:52:46.540Z
Answers.LastActivityDate: 2020-12-11T09:31:06.000Z
Answers.LastEditDate: 2020-12-11T09:31:06.000Z
Answers.UserDisplayName: Alex89
Body: <p>I'm using the headless Craft together with decoupled frontend on Nuxt.js.
  I have to implement Craft Commerce 3 cart logic on the frontend, for that purpose I'm using graphQl/axios requests.</p>
  <p>However each time I call <code>http://example.com?action=commerce/cart/update-cart&amp;note=from+ajax</code> with cart payload it returns me a new cart with added product (doesn't update the current cart, but returns a new cart each time).</p>
  <p>Is there something I'm missing in my payload/headers to keep the same cart?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-09T22:04:25.627Z
Comments.Text: You're not using Commerce Lite by any chance are you - it has a 1 item in cart limit, so would probably behave like that.  You need Pro for multiple items in a cart...
Comments.UserDisplayName: Jeremy Daalder
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-12-10T09:41:47.033Z
Comments.Text: Currently in development stage I'm using Pro trial version, also the same request done in Postman gives the proper result (updates the same cart). Even if I call action=commerce/cart/load-cart&note=from+ajax&number={number} first to load the current cart, it still returns me a new one on update. May it be something related to cookies/session?
Comments.UserDisplayName: Alex89
Tags: <plugin-craftcommerce3><vue>
Title: Getting a new cart after adding the product in decoupled frontend
ThreadText: # Getting a new cart after adding the product in decoupled frontend
  
  (Asked by: username_0 on 2020-12-09)
  
  I'm using the headless Craft together with decoupled frontend on Nuxt.js.
  I have to implement Craft Commerce 3 cart logic on the frontend, for that purpose I'm using graphQl/axios requests.
  
  However each time I call `http://example.com?action=commerce/cart/update-cart&note=from+ajax` with cart payload it returns me a new cart with added product (doesn't update the current cart, but returns a new cart each time).
  
  Is there something I'm missing in my payload/headers to keep the same cart?
  
  **Tags:** plugin-craftcommerce3, vue
  
  > **Comments:**
  > **username_1**: You're not using Commerce Lite by any chance are you - it has a 1 item in cart limit, so would probably behave like that.  You need Pro for multiple items in a cart...  
  > **username_0**: Currently in development stage I'm using Pro trial version, also the same request done in Postman gives the proper result (updates the same cart). Even if I call action=commerce/cart/load-cart&note=from+ajax&number={number} first to load the current cart, it still returns me a new one on update. May it be something related to cookies/session?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2020-12-11. Score: 1
  
  UPD 2: Spending more hours gave me the solution:
  
  It seems like Ajax generates a new sessionId with each call, so it's impossible to preserve cart along with session Id in that case. As workaround I was trying to pass session id cookie manually, but it was rejected by Axios.
  
  What I have found is that you can actually call `action=commerce/cart/get-cart&note=from+ajax` as POST request with passing the following body:
  
  ```
  {
      "orderNumber": "{{ number of a cart }}"
  }
  
  ```
  
  So it can be used to load the cart you actually need. Therefore there is no need to use `?action=commerce/cart/load-cart&note=from+ajax&number={number}` cause it works only with sessions.
  
  The only thing you need is to store cart number in your localStorage or store to pass it as body parameter
  
  
  ---
  
  ### Answer by username_0 on 2020-12-10. Score: 1
  
  UPD: after some hours of research I found the solution in this topic:
  
  [CORS preflight check failing for AJAX login form on different domain](https://craftcms.stackexchange.com/questions/35791/cors-preflight-check-failing-for-ajax-login-form-on-different-domain)
  
  Also I had to pass the `orderNumber` parameter with the value of cart number in payload.
  
  However I have a different issue now. First I call `?action=commerce/cart/load-cart&note=from+ajax&number={number}` to load my stored card into the session. Then I call `action=commerce/cart/get-cart&note=from+ajax` to get the content of the cart I loaded in step one, but it returns me a new empty cart. I suppose there is something to deal with the CraftSessionId in headers, am I right?
  
  [![enter image description here](https://i.sstatic.net/vyUsB.png)](https://i.sstatic.net/vyUsB.png)
  
  [![enter image description here](https://i.sstatic.net/TXCJi.png)](https://i.sstatic.net/TXCJi.png)
  
  
  ---
  
  