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:
@@ -118,3 +118,5 @@ This is necessary, as only products matching the cart's sales channel(s) can be
|
||||
## Associate Customer with Cart
|
||||
|
||||
When the cart is created for a logged-in customer, it's automatically associated with that customer.
|
||||
|
||||
However, if the cart is created for a guest customer, then the customer logs in, then you have to set the cart's customer as explained in [this guide](../update/page.mdx#set-carts-customer).
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user