docs: add details on updating a cart's customer (#10226)

Should be merged after releasing v2.0.5

Closes DX-1096
This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-11-25 11:56:35 +00:00
1 parent 01b0a84898
commit ae1c607f4e
12 files changed
+110 -65

No files matched your search

@@ -46,3 +46,46 @@ fetch(`http://localhost:9000/store/carts/${cartId}`, {
```
The Update Cart API route accepts a `region_id` request body parameter, whose value is the new region to associate with the cart.
---
## Set Cart's Customer
You might need to change the cart's customer in two cases:
- You created the cart for the customer as a guest, then they logged-in, so you want to associate the cart with them as a registered customer.
- You're transfering the cart from one customer to another, which is useful in company setups, such as when implementing B2B commerce applicatons.
To set or change the cart's customer, send an authenticated `POST` request to the Set Cart's Customer API route:
<Note>
This API route is only available after [Medusa v2.0.5](https://github.com/medusajs/medusa/releases/tag/v2.0.5).
</Note>
```ts
fetch(`http://localhost:9000/store/carts/${cartId}/customer`, {
credentials: "include",
method: "POST",
headers: {
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then(({ cart }) => {
// use cart...
console.log(cart)
})
```
To send an authenticated request, either use `credentials: include` if the customer is already authenticated with a cookie session, or pass the Authorization Bearer token in the request's header.
<Note title="Tip">
Learn more about authenticating customers in [this guide](../../customers/login/page.mdx).
</Note>
The cart is now associated with the logged-in customer.