From 4bc9b8b740165bf30cd92a6d61d5740f7e6a5d6b Mon Sep 17 00:00:00 2001 From: Andrii Beziazychnyi Date: Sat, 24 Oct 2020 03:04:50 +0300 Subject: [PATCH 1/2] Fix the topic `mergeCarts` mutation according to PR magento2#30633 --- .../v2.4/graphql/mutations/merge-carts.md | 72 +++++++++++++++++-- 1 file changed, 66 insertions(+), 6 deletions(-) diff --git a/src/guides/v2.4/graphql/mutations/merge-carts.md b/src/guides/v2.4/graphql/mutations/merge-carts.md index 6fd42d1e53b..e7d7fc00023 100644 --- a/src/guides/v2.4/graphql/mutations/merge-carts.md +++ b/src/guides/v2.4/graphql/mutations/merge-carts.md @@ -7,11 +7,18 @@ 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. -Use the [`customerCart` query]({{page.baseurl}}/graphql/queries/customer-cart.html) to determine the value of the `destination_cart_id` attribute. - ## Syntax -`mergeCarts(source_cart_id: String!, destination_cart_id: String!): Cart!` +```graphql +mutation { + mergeCarts( + source_cart_id: String! + destination_cart_id: String + ) { + Cart! + } +} +``` ## Example usage @@ -21,7 +28,60 @@ In the following example, the customer had one Overnight Duffle in the cart (`CY ```graphql mutation { - mergeCarts(source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O", destination_cart_id: "CYmiiQRjPVc2gJUc5r7IsBmwegVIFO43") { + mergeCarts( + source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O", + destination_cart_id: "CYmiiQRjPVc2gJUc5r7IsBmwegVIFO43" + ) { + items { + id + product { + name + sku + } + quantity + } + } +} +``` + +**Response:** + +```json +{ + "data": { + "mergeCarts": { + "items": [ + { + "id": "14", + "product": { + "name": "Overnight Duffle", + "sku": "24-WB07" + }, + "quantity": 2 + }, + { + "id": "17", + "product": { + "name": "Radiant Tee", + "sku": "WS12" + }, + "quantity": 1 + } + ] + } + } +} +``` + +This example shows how you can execute the previous request without `destination_cart_id`. + +**Request:** + +```graphql +mutation { + mergeCarts( + source_cart_id: "mPKE05OOtcxErbk1Toej6gw6tcuxvT9O" + ) { items { id product { @@ -67,7 +127,7 @@ mutation { Attribute | Data Type | Description --- | --- | --- -`destination_cart_id` | String! | The ID of the logged-in customer's cart +`destination_cart_id` | String | The ID of the logged-in customer's cart. If you do not specify a value the ID will be gotten automatically by the logged-in customer. `source_cart_id` | String! | The ID of the guest cart ## Output attributes @@ -89,7 +149,7 @@ Attribute | Data Type | Description Error | Description --- | --- `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. -`Required parameter "destination_cart_id" is missing` | The `destination_cart_id` attribute contains an empty value. `Required parameter "source_cart_id" is missing` | The `source_cart_id` attribute contains an empty value. `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. `The current user cannot perform operations on cart` | The authorized customer tried to merge a guest cart into the cart of another customer. +`Could not create empty cart for customer` | The system could not create an empty cart for logged-in customer \ No newline at end of file From c6d6701aa545360715f33587758dac53cc16a0fa Mon Sep 17 00:00:00 2001 From: Kevin Harper Date: Fri, 23 Oct 2020 21:05:17 -0500 Subject: [PATCH 2/2] Update merge-carts.md --- src/guides/v2.4/graphql/mutations/merge-carts.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/guides/v2.4/graphql/mutations/merge-carts.md b/src/guides/v2.4/graphql/mutations/merge-carts.md index e7d7fc00023..bdf9e71b57b 100644 --- a/src/guides/v2.4/graphql/mutations/merge-carts.md +++ b/src/guides/v2.4/graphql/mutations/merge-carts.md @@ -73,7 +73,7 @@ mutation { } ``` -This example shows how you can execute the previous request without `destination_cart_id`. +The following example executes the previous request without specifying `destination_cart_id`. **Request:** @@ -127,7 +127,7 @@ mutation { Attribute | Data Type | Description --- | --- | --- -`destination_cart_id` | String | The ID of the logged-in customer's cart. If you do not specify a value the ID will be gotten automatically by the logged-in customer. +`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. `source_cart_id` | String! | The ID of the guest cart ## Output attributes @@ -152,4 +152,4 @@ Error | Description `Required parameter "source_cart_id" is missing` | The `source_cart_id` attribute contains an empty value. `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. `The current user cannot perform operations on cart` | The authorized customer tried to merge a guest cart into the cart of another customer. -`Could not create empty cart for customer` | The system could not create an empty cart for logged-in customer \ No newline at end of file +`Could not create empty cart for customer` | The system could not create an empty cart for the logged-in customer