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 3 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
108 changes: 108 additions & 0 deletions src/guides/v2.4/graphql/mutations/assign-customer-to-guest-cart.md
@@ -0,0 +1,108 @@
---
group: graphql
title: assignCustomerToGuestCart mutation
contributor_name: Atwix
contributor_link: https://www.atwix.com/
---

The `assignCustomerToGuestCart` mutation assigns a logged in customer and merge customer's shopping cart items to the specified guest shopping cart.
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved

keharper marked this conversation as resolved.
Show resolved Hide resolved
The customer must be logged in (You must specify the customer’s authorization token in the headers).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this line with the standard "This mutation requires a valid customer authentication token." and move it to the bottom of this section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


If this mutation is successful, the customer's shopping cart becomes inactive and all the products it contains are added to the contents of the guest cart (the active one).
Customer now is assigned to that active cart.

*Note:*
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved
Customer cart becomes inactive and the guest cart remains active; but for guest cart new `masked_id` is being generated.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are masked_id and quote_id mentioned here, when neither are part of the request or response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @keharper , I mentioned them because I think it's a useful information for the developers, who can be confused why there is no old masked_id in the database, but a new one appeared instead.
I can remove this note if you think that it's unnecessary information.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Customer cart becomes inactive and the guest cart remains active; but for guest cart new `masked_id` is being generated.
The `masked_id` of the guest cart contains a new value. The `quote_id` remains the same.

`quote_id` remains same.
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved

karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved
The other similar mutation, [mergeCarts]({{page.baseurl}}/graphql/mutations/merge-carts.html), just merges cart items.
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved
Unlike `assignCustomerToGuestCart`, it transfers the contents of a guest cart into the customer's cart. The mutation deletes the original guest cart.

## Syntax

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

## Example usage

Assuming that there is a logged in customer who has an item in the cart, this call will merge customer's cart item to the specified guest shopping cart (which also contains an item).
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved

**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.
3 changes: 3 additions & 0 deletions src/guides/v2.4/graphql/mutations/merge-carts.md
Expand Up @@ -7,6 +7,9 @@ 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.

There is a similar [assignCustomerToGuestCart]({{page.baseurl}}/graphql/mutations/assign-customer-to-guest-cart.html) mutation which works in a different way: it assigns a logged in customer and merge customer's shopping cart items to the guest shopping cart.
karyna-tsymbal-atwix marked this conversation as resolved.
Show resolved Hide resolved
Customer cart becomes inactive and the guest cart remains active.

## Syntax

```graphql
Expand Down