Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit c7ae10c

Browse files
andrewbesskeharper
andauthored
Fix the topic mergeCarts mutation according to PR magento2#30633 (#8121)
* Fix the topic `mergeCarts` mutation according to PR magento2#30633 * Update merge-carts.md Co-authored-by: Kevin Harper <keharper@users.noreply.github.com>
1 parent 5836415 commit c7ae10c

File tree

1 file changed

+66
-6
lines changed

1 file changed

+66
-6
lines changed

src/guides/v2.4/graphql/mutations/merge-carts.md

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ The `mergeCarts` mutation transfers the contents of a guest cart into the cart o
77

88
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.
99

10-
Use the [`customerCart` query]({{page.baseurl}}/graphql/queries/customer-cart.html) to determine the value of the `destination_cart_id` attribute.
11-
1210
## Syntax
1311

14-
`mergeCarts(source_cart_id: String!, destination_cart_id: String!): Cart!`
12+
```graphql
13+
mutation {
14+
mergeCarts(
15+
source_cart_id: String!
16+
destination_cart_id: String
17+
) {
18+
Cart!
19+
}
20+
}
21+
```
1522

1623
## Example usage
1724

@@ -21,7 +28,60 @@ In the following example, the customer had one Overnight Duffle in the cart (`CY
2128

2229
```graphql
2330
mutation {
24-
mergeCarts(source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O", destination_cart_id: "CYmiiQRjPVc2gJUc5r7IsBmwegVIFO43") {
31+
mergeCarts(
32+
source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O",
33+
destination_cart_id: "CYmiiQRjPVc2gJUc5r7IsBmwegVIFO43"
34+
) {
35+
items {
36+
id
37+
product {
38+
name
39+
sku
40+
}
41+
quantity
42+
}
43+
}
44+
}
45+
```
46+
47+
**Response:**
48+
49+
```json
50+
{
51+
"data": {
52+
"mergeCarts": {
53+
"items": [
54+
{
55+
"id": "14",
56+
"product": {
57+
"name": "Overnight Duffle",
58+
"sku": "24-WB07"
59+
},
60+
"quantity": 2
61+
},
62+
{
63+
"id": "17",
64+
"product": {
65+
"name": "Radiant Tee",
66+
"sku": "WS12"
67+
},
68+
"quantity": 1
69+
}
70+
]
71+
}
72+
}
73+
}
74+
```
75+
76+
The following example executes the previous request without specifying `destination_cart_id`.
77+
78+
**Request:**
79+
80+
```graphql
81+
mutation {
82+
mergeCarts(
83+
source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O"
84+
) {
2585
items {
2686
id
2787
product {
@@ -67,7 +127,7 @@ mutation {
67127

68128
Attribute | Data Type | Description
69129
--- | --- | ---
70-
`destination_cart_id` | String! | The ID of the logged-in customer's cart
130+
`destination_cart_id` | String | The ID of the logged-in customer's cart. If you do not specify a value, the mutation determines the customer's cart ID and uses that value.
71131
`source_cart_id` | String! | The ID of the guest cart
72132

73133
## Output attributes
@@ -89,7 +149,7 @@ Attribute | Data Type | Description
89149
Error | Description
90150
--- | ---
91151
`Current user does not have an active cart.` | The `mergeCarts` mutation deactivates the guest cart specified in the `source_cart_id` after merging. The guest cannot make any further operations with it.
92-
`Required parameter "destination_cart_id" is missing` | The `destination_cart_id` attribute contains an empty value.
93152
`Required parameter "source_cart_id" is missing` | The `source_cart_id` attribute contains an empty value.
94153
`The current customer isn't authorized.` | The current customer is not currently logged in, or the customer's token does not exist in the `oauth_token` table, or you tried to merge two guest carts.
95154
`The current user cannot perform operations on cart` | The authorized customer tried to merge a guest cart into the cart of another customer.
155+
`Could not create empty cart for customer` | The system could not create an empty cart for the logged-in customer

0 commit comments

Comments
 (0)