From f7932f11ed8334180640de573efb3090e50c9f4d Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 22 Oct 2024 20:40:39 +0300 Subject: [PATCH] docs: fix details on setting / updating customer ID in cart (#9689) --- .../cart/create/page.mdx | 22 +++---------------- .../cart/update/page.mdx | 6 +++++ www/apps/resources/generated/edit-dates.mjs | 4 ++-- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/www/apps/resources/app/storefront-development/cart/create/page.mdx b/www/apps/resources/app/storefront-development/cart/create/page.mdx index 446d909119..307d988600 100644 --- a/www/apps/resources/app/storefront-development/cart/create/page.mdx +++ b/www/apps/resources/app/storefront-development/cart/create/page.mdx @@ -117,24 +117,8 @@ This is necessary, as only products matching the cart's sales channel(s) can be ## Associate Customer with Cart -When creating the cart, you can associate the logged-in customer's ID with the cart by passing a `customer_id` request body parameter. +When the cart is created for a logged-in customer, it's automatically associated with that customer. -For example: +If the customer is a guest, then later logs in, you can set their ID on the cart by updating it. -export const customerHighlights = [ - ["5", "customer.id", "Assuming you have the customer object."] -] - -```ts highlights={customerHighlights} -fetch(`http://localhost:9000/store/carts`, { - // ... - body: JSON.stringify({ - // ... - customer_id: customer.id, - }), -}) -.then((res) => res.json()) -.then(({ cart }) => { - localStorage.setItem("cart_id", cart.id) -}) -``` +Refer to [this documentation](../update/page.mdx#update-carts-customer) to learn how to set the customer of a cart. \ No newline at end of file diff --git a/www/apps/resources/app/storefront-development/cart/update/page.mdx b/www/apps/resources/app/storefront-development/cart/update/page.mdx index e8a3a972a0..03e0bf445b 100644 --- a/www/apps/resources/app/storefront-development/cart/update/page.mdx +++ b/www/apps/resources/app/storefront-development/cart/update/page.mdx @@ -53,6 +53,12 @@ The Update Cart API route accepts a `region_id` request body parameter, whose va If a guest customer logs in, you must update the cart to be associated with the logged-in customer. + + +You can't change the `customer_id` if the cart was associated with a customer previously. + + + For example: export const updateCustomerHighlights = [ diff --git a/www/apps/resources/generated/edit-dates.mjs b/www/apps/resources/generated/edit-dates.mjs index c200d40de2..7a100f1335 100644 --- a/www/apps/resources/generated/edit-dates.mjs +++ b/www/apps/resources/generated/edit-dates.mjs @@ -152,10 +152,10 @@ export const generatedEditDates = { "app/service-factory-reference/tips/filtering/page.mdx": "2024-07-31T17:01:33+03:00", "app/service-factory-reference/page.mdx": "2024-07-26T14:40:56+00:00", "app/storefront-development/cart/context/page.mdx": "2024-09-11T10:08:05.194Z", - "app/storefront-development/cart/create/page.mdx": "2024-09-11T10:08:05.195Z", + "app/storefront-development/cart/create/page.mdx": "2024-10-21T07:40:27.947Z", "app/storefront-development/cart/manage-items/page.mdx": "2024-09-11T10:10:54.932Z", "app/storefront-development/cart/retrieve/page.mdx": "2024-09-11T10:12:55.828Z", - "app/storefront-development/cart/update/page.mdx": "2024-09-11T10:12:47.704Z", + "app/storefront-development/cart/update/page.mdx": "2024-10-21T07:41:21.046Z", "app/storefront-development/cart/page.mdx": "2024-06-11T11:56:37+03:00", "app/storefront-development/checkout/address/page.mdx": "2024-09-11T09:40:02.899Z", "app/storefront-development/checkout/complete-cart/page.mdx": "2024-09-11T09:40:48.531Z",