Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add documentation for assignCustomerToGuestCart mutation #9252

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/_data/toc/graphql.yml
Expand Up @@ -295,6 +295,10 @@ pages:
url: /graphql/mutations/assign-compare-list-to-customer.html
exclude_versions: ["2.3"]

- label: assignCustomerToGuestCart mutation
url: /graphql/mutations/assign-customer-to-guest-cart.html
exclude_versions: [ "2.3" ]

- label: changeCustomerPassword mutation
url: /graphql/mutations/change-customer-password.html

Expand Down
104 changes: 104 additions & 0 deletions src/guides/v2.4/graphql/mutations/assign-customer-to-guest-cart.md
@@ -0,0 +1,104 @@
---
group: graphql
title: assignCustomerToGuestCart mutation
contributor_name: Atwix
contributor_link: https://www.atwix.com/
---

The `assignCustomerToGuestCart` mutation merges a logged-in customer's shopping cart into the specified guest cart. The mutation inactivates the customer's shopping cart and moves the products to the guest cart. The guest cart is then assigned to the customer.

{:.bs-callout-info}
The `masked_id` of the guest cart contains a new value. The `quote_id` remains the same.

This mutation requires a valid [customer authentication token]({{page.baseurl}}/graphql/mutations/generate-customer-token.html).

{:.bs-callout-info}
Use the [mergeCarts]({{page.baseurl}}/graphql/mutations/merge-carts.html) mutation to transfer the contents of a guest cart into a customer's cart.

keharper marked this conversation as resolved.
Show resolved Hide resolved
## Syntax

```graphql
mutation {
assignCustomerToGuestCart(
cart_id: String!
) {
Cart!
}
}
```

## Example usage

In the following example, the customer and guest carts each contain one item. The mutation merges the customer's cart to the guest cart. As a result, the guest cart contains two items.

**Request:**

```graphql
mutation {
assignCustomerToGuestCart(
cart_id: "MDYKgqIdWMKr7VD1zlYwxrB7kuX8lR5s"
) {
items {
quantity
product {
sku
}
}
}
}
```

**Response:**

```json
{
"data": {
"assignCustomerToGuestCart": {
"items": [
{
"quantity": 1,
"product": {
"sku": "customer_item"
}
},
{
"quantity": 1,
"product": {
"sku": "guest_item"
}
}
]
}
}
}
```

## Input attributes

Attribute | Data Type | Description
--- | --- | ---
`cart_id` | String! | The unique ID that identifies the guest's cart

## Output attributes

The `assignCustomerToGuestCart` mutation returns a `Cart` object.

Attribute | Data Type | Description
--- | --- | ---
`cart` |[Cart!](#CartObject) | Describes the contents of the specified shopping cart

### Cart object {#CartObject}

{% include graphql/cart-object-24.md %}

[Cart query output]({{page.baseurl}}/graphql/queries/cart.html#cart-output) provides more information about the `Cart` object.

## Errors

Error | Description
--- | ---
`The current customer isn't authorized.` | The current customer is not currently logged in.
`Unable to assign the customer to the guest cart` | The current customer can't be assigned to the provided guset cart.
`The cart isn't active` | The cart with the specified cart ID is unavailable, because the items have been purchased and the cart ID becomes inactive.
`Could not find a cart with ID "XXX"` | The specified `cart_id` value does not exist in the `quote_id_mask` table.
`The current user cannot perform operations on cart "XXX"` | Tried to assign the customer to the customer's cart.
4 changes: 4 additions & 0 deletions src/guides/v2.4/graphql/mutations/merge-carts.md
Expand Up @@ -7,6 +7,10 @@ The `mergeCarts` mutation transfers the contents of a guest cart into the cart o

The mutation retains any items that were already in the logged-in customer's cart. If both the guest and customer carts contain the same item, `mergeCarts` adds the quantities. Upon success, the mutation deletes the original guest cart.

{:.bs-callout-info}
Use the [assignCustomerToGuestCart]({{page.baseurl}}/graphql/mutations/assign-customer-to-guest-cart.html) mutation to assign the contents of a logged-in customer's cart to a guest cart.
Customer cart becomes inactive and the guest cart remains active.

## Syntax

```graphql
Expand Down