From 5e223795e37221c2d52168ee327e411ee7f9ac94 Mon Sep 17 00:00:00 2001 From: Erik Marr Date: Thu, 28 Feb 2019 11:49:47 -0600 Subject: [PATCH 1/6] updating with mutations --- guides/v2.3/graphql/reference/quote.md | 544 ++++++++++++++++++++++++- 1 file changed, 539 insertions(+), 5 deletions(-) diff --git a/guides/v2.3/graphql/reference/quote.md b/guides/v2.3/graphql/reference/quote.md index a53e84675d6..a784ce5d35e 100644 --- a/guides/v2.3/graphql/reference/quote.md +++ b/guides/v2.3/graphql/reference/quote.md @@ -9,14 +9,147 @@ A quote represents the contents of a customer's shopping cart. It is responsible * Determining estimated shipping costs * Calculating subtotals, computing additional costs, applying coupons, and determining the payment method -## Mutations +## Query +Use the `Cart` query to retrieve information about a particular cart. + +### Syntax + +`cart: Cart` + +### Cart attributes +The cart object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`applied_coupon` | code | Contains the coupon code if used +`billing_address` | [CartAddress](#cartAddressAttributes) | Contains the billing address specified in the customer's cart +`cart_id` | String | The unique ID that identifies the customer's cart +`items` | [CartItemInterface](#cartItemsInterface) | Contains the items in the customer's cart +`shipping_addresses` | [CartAddress] | Contains one or more shipping addresses + +### Cart address attributes {#cartAddressAttributes} +The cart address object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`address_type` | [AddressTypeEnum] | Specifies if the type of address is shipping or billing +`cart_items` | [CartItemQuantity] | An array of the cart item IDs and quantity of each item +`city` | String | The city specified for the shipping or billing address +`company` | String | The company specified for the shipping or billing address +`country` | [CartAddressCountry] | The country code and label for the shipping or billing address +`customer_notes` | String | Comments made to the customer that accompanies the order +`firstname` | String | The customer's first name +`items_weight` | Float | The total weight of the items in the cart +`lastname` | String | The customer's last name +`postcode` | String | The postal code for the shipping or billing address +`region` | [CartAddressRegion] | An object containing the region name, region code, and region ID +`street` | [String] | The street for the shipping or billing address +`telephone` | String | The telephone number for the shipping or billing address + +### Cart item interface attributes {#cartItemsInterface} +The cart item interface object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`id` | String | ID of the item +`product` | [ProductInterface]({{ page.baseurl }}/graphql/reference/product-interface-implementations.html) | Contains attributes that are common to all types of products +`qty` | Float | The number of items in the cart + + + +### Example usage + +The following returns information about a cart given a `cart_id`. Note that the `cart_id` specified is for demonstration purposes only. You will need to [generate](#createEmptyCart) your own `cart_id` for this example to work. + +**Request** + +``` text +{ + cart(cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C") { + cart_id + billing_address { + lastname, + firstname, + postcode + } + items { + id, + qty + } + shipping_addresses { + company + postcode + lastname + firstname + } + } +} +``` +**Response** + +```json +{ + "data": { + "cart": { + "cart_id": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C", + "billing_address": { + "lastname": "Roll", + "firstname": "Bob", + "postcode": "78759" + }, + "items": [ + { + "id": "22", + "qty": 1 + } + ], + "shipping_addresses": [ + { + "company": "Magento", + "postcode": "78759", + "lastname": "Roll", + "firstname": "Bob" + } + ] + } + } +} +``` -Magento 2.3.0 supports the `createEmptyCart` mutation only. +## Mutations +Use the `quote` mutations to create a cart, apply or remove a coupon from a cart, add products to a cart, and set shipping and billing information to a cart. -### Create an empty cart +### Create an empty cart {#createEmptyCart} The `createEmptyCart` mutation creates an empty shopping cart for a guest or logged in customer. If you are creating a cart for a logged in customer, you must include the customer's authorization token in the header of the request. +#### Syntax + +`mutation: createEmptyCart` + +#### Example usage + +The following call creates a new, empty shopping cart. + **Request** ``` text @@ -27,12 +160,413 @@ mutation { **Response** -The response is the quote ID, which is sometimes called the cart ID. +The response is the quote ID, which is sometimes called the cart ID. The remaining examples in this topic will use this cart ID. ```json { "data": { - "createEmptyCart": "6XZA7q1ooLEI0jLz8DfFrfruEqgxGzlt" + "createEmptyCart": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"} } } ``` + +### Adding and removing coupons from a cart +{:.no_toc} + +You can use mutations to add or remove coupons from a specified cart. + +### Coupon attributes +The coupon object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`cart_id` | String | The unique ID that identifies the customer's cart +`coupon_code` | String | The coupon code + +### Apply coupon to cart + +Adds a coupon code to a cart. + +#### Syntax + +`mutation: applyCouponToCart` + +#### Example usage + +The following call adds a coupon code called `test2019` to a cart. + +**Request** + +``` text +mutation { + applyCouponToCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C", coupon_code: "test2019"}) { + cart { + applied_coupon { + code + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "applyCouponToCart": { + "cart": { + "applied_coupon": { + "code": "test2019" + } + } + } + } +} + +``` + +### Remove coupon from cart + +Removes a coupon from the specified cart. + +#### Syntax + +`mutation: removeCouponFromCart` + +#### Example usage + +The following example removes a coupon from the cart. + +**Request** + +``` text +mutation { + removeCouponFromCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"}) { + cart { + applied_coupon { + code + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "removeCouponFromCart": { + "cart": { + "applied_coupon": { + "code": "test2019" + } + } + } + } +} +``` + +### Adding products to cart +{:.no_toc} + +Adds simple items to a specific cart. + +### Add simple products to cart attributes +The Add simple products to cart object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`cartItems` | [SimpleProductCartItemInput] | The list of items to add to the cart +`cart_id` | String | The unique ID that identifies the customer's cart + +#### Syntax + +`mutation: addSimpleProductsToCart` + +#### Example usage + +The following example adds two Joust Duffle Bags to the cart. + +**Request** + +``` text +mutation { + addSimpleProductsToCart( + input: { + cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C", + cartItems: [ + { + data: { + qty: 2 + sku: "24-MB01" + } + } + ] + } + ) { + cart { + cart_id + } + } +} +``` + +**Response** + +```json +{ + "data": { + "addSimpleProductsToCart": { + "cart": { + "cart_id": "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C" + } + } + } +} +``` + + +### Updating billing and shipping information +{:.no_toc} + +You can set the billing and shipping addresses on a cart and specify shipping methods. + +### Set billing address on cart attributes +The Set billing address on cart object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`billing_address` | [BillingAddressInput](#billingAddressInput) | The list of items to add to the cart +`cart_id` | String | The unique ID that identifies the customer's cart + +### Set billing address input attributes {#billingAddressInput} +The Set billing address input object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`address` | [CartAddressInput](#cartAddressInput) | The list of items to add to the cart +`customer_address_id` | Int | The unique ID that identifies the customer's address +`use_for_shipping` | Boolean | Specifies whether to use the billing address for the shipping address (`True`/`False`) + +### Cart address input attributes {#cartAddressInput} +The Cart address input object can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`city` | String | The city specified for the billing address +`company` | String | The company specified for the billing address +`country_code` | String | The country code and label for the billing address +`customer_notes` | String | Comments made to the customer that accompanies the order +`firstname` | String | The customer's first name +`lastname` | String | The customer's last name +`postcode` | String | The postal code for the billing address +`region` | String | The region code and label for the billing address +`save_in_address_book` | Boolean | Specifies whether to save the address (`True`/`False`) +`street` | [String] | The street for the billing address +`telephone` | String | The telephone number for the billing address + +### Set billing address on cart + +Use the `setBillingAddressOnCart` mutation to set a new billing address for a specific cart. + +#### Syntax + +`mutation: setBillingAddressOnCart` + +#### Example usage + +The following example creates a new billing address for a specific cart. + +**Request** + +``` text +mutation { + setBillingAddressOnCart( + input: { + cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C" + billing_address: { + address: { + firstname: "test firstname" + lastname: "test lastname" + company: "test company" + street: ["test street 1", "test street 2"] + city: "test city" + region: "test region" + postcode: "887766" + country_code: "US" + telephone: "88776655" + save_in_address_book: false + } + } + } + ) { + cart { + billing_address { + firstname + lastname + company + street + city + postcode + telephone + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "setBillingAddressOnCart": { + "cart": { + "billing_address": { + "firstname": "test firstname", + "lastname": "test lastname", + "company": "test company", + "street": [ + "test street 1", + "test street 2" + ], + "city": "test city", + "postcode": "887766", + "telephone": "88776655" + } + } + } + } +} +``` + +### Set shipping address on cart + +Use the `setShippingAddressesOnCart` mutation to set a new shipping address for a specific cart. + +#### Syntax + +`mutation: setShippingAddressOnCart` + +#### Example usage + +The following example creates a new shipping address for a specific cart. + +**Request** + +``` text +mutation { + setShippingAddressesOnCart( + input: { + cart_id: "OOJVZU6tSSQ8vLoXqx9pDMZili3uQ8Hi" + shipping_addresses: [ + { + address: { + firstname: "test firstname" + lastname: "test lastname" + company: "test company" + street: ["test street 1", "test street 2"] + city: "test city" + region: "test region" + postcode: "887766" + country_code: "US" + telephone: "88776655" + save_in_address_book: false + } + } + ] + } + ) { + cart { + shipping_addresses { + firstname + lastname + company + street + city + postcode + telephone + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "setShippingAddressesOnCart": { + "cart": { + "shipping_addresses": [ + { + "firstname": "test firstname", + "lastname": "test lastname", + "company": "test company", + "street": [ + "test street 1", + "test street 2" + ], + "city": "test city", + "postcode": "887766", + "telephone": "88776655" + } + ] + } + } + } +} +``` + + \ No newline at end of file From 13d9f4c7d21a1067ce75a3af892acdcccf5506da Mon Sep 17 00:00:00 2001 From: Erik Marr Date: Fri, 1 Mar 2019 13:36:37 -0600 Subject: [PATCH 2/6] entered edits from Kevin --- guides/v2.3/graphql/reference/quote.md | 97 +++++++++++++++----------- 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/guides/v2.3/graphql/reference/quote.md b/guides/v2.3/graphql/reference/quote.md index a784ce5d35e..df1c1018649 100644 --- a/guides/v2.3/graphql/reference/quote.md +++ b/guides/v2.3/graphql/reference/quote.md @@ -14,10 +14,10 @@ Use the `Cart` query to retrieve information about a particular cart. ### Syntax -`cart: Cart` +`cart(cart_id: String!): Cart` ### Cart attributes -The cart object can contain the following attributes: +The `Cart` object can contain the following attributes: Attribute | Data Type | Description --- | --- | --- @@ -25,15 +25,15 @@ Attribute | Data Type | Description `billing_address` | [CartAddress](#cartAddressAttributes) | Contains the billing address specified in the customer's cart `cart_id` | String | The unique ID that identifies the customer's cart `items` | [CartItemInterface](#cartItemsInterface) | Contains the items in the customer's cart -`shipping_addresses` | [CartAddress] | Contains one or more shipping addresses +`shipping_addresses` | [CartAddress](#cartAddressAttributes) | Contains one or more shipping addresses ### Cart address attributes {#cartAddressAttributes} -The cart address object can contain the following attributes: +The `CartAddress` object can contain the following attributes: Attribute | Data Type | Description --- | --- | --- -`address_type` | [AddressTypeEnum] | Specifies if the type of address is shipping or billing -`cart_items` | [CartItemQuantity] | An array of the cart item IDs and quantity of each item +`address_type` | AddressTypeEnum | Specifies if the type of address is SHIPPING or BILLING +`cart_items` | CartItemQuantity | Contains the cart item IDs and quantity of each item `city` | String | The city specified for the shipping or billing address `company` | String | The company specified for the shipping or billing address `country` | [CartAddressCountry] | The country code and label for the shipping or billing address @@ -42,12 +42,12 @@ Attribute | Data Type | Description `items_weight` | Float | The total weight of the items in the cart `lastname` | String | The customer's last name `postcode` | String | The postal code for the shipping or billing address -`region` | [CartAddressRegion] | An object containing the region name, region code, and region ID +`region` | CartAddressRegion | An object containing the region name, region code, and region ID `street` | [String] | The street for the shipping or billing address `telephone` | String | The telephone number for the shipping or billing address ### Cart item interface attributes {#cartItemsInterface} -The cart item interface object can contain the following attributes: +The `CartItemInterface` object can contain the following attributes: Attribute | Data Type | Description --- | --- | --- @@ -57,17 +57,16 @@ Attribute | Data Type | Description \ No newline at end of file +``` \ No newline at end of file From 12713d759eabd2276f616fe439d03d30bff7a955 Mon Sep 17 00:00:00 2001 From: Erik Marr Date: Sun, 3 Mar 2019 10:51:02 -0600 Subject: [PATCH 4/6] entered more edits from kevin --- guides/v2.3/graphql/reference/quote.md | 112 +++++++++---------------- 1 file changed, 40 insertions(+), 72 deletions(-) diff --git a/guides/v2.3/graphql/reference/quote.md b/guides/v2.3/graphql/reference/quote.md index 7605c41746e..152f793f52d 100644 --- a/guides/v2.3/graphql/reference/quote.md +++ b/guides/v2.3/graphql/reference/quote.md @@ -55,26 +55,6 @@ Attribute | Data Type | Description `product` | [ProductInterface]({{ page.baseurl }}/graphql/reference/product-interface-implementations.html) | Contains attributes that are common to all types of products `qty` | Float | The number of items in the cart - - ### Example usage The following returns information about a cart given a `cart_id`. Note that the `cart_id` specified is for demonstration purposes only. You will need to [generate](#createEmptyCart) your own `cart_id` for this example to work. @@ -86,22 +66,23 @@ The following returns information about a cart given a `cart_id`. Note that the cart(cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C") { cart_id billing_address { - lastname, - firstname, + lastname + firstname postcode - } + } items { - id, + id qty } shipping_addresses { - company + company postcode lastname - firstname + firstname } } } + ``` **Response** @@ -137,6 +118,9 @@ The following returns information about a cart given a `cart_id`. Note that the ## Mutations +### Create an empty cart {#createEmptyCart} +{:.no_toc} + The `createEmptyCart` mutation creates an empty shopping cart for a guest or logged in customer. If you are creating a cart for a logged in customer, you must include the customer's authorization token in the header of the request. #### Syntax @@ -334,22 +318,6 @@ mutation { } } ``` - ### Updating billing and shipping information {:.no_toc} @@ -390,7 +358,7 @@ Attribute | Data Type | Description `street` | [String] | The street for the billing address `telephone` | String | The telephone number for the billing address -### Set billing address on cart +### Set the billing address on a cart Use the `setBillingAddressOnCart` mutation to set a new billing address for a specific cart. @@ -411,16 +379,16 @@ mutation { cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C" billing_address: { address: { - firstname: "test firstname" - lastname: "test lastname" - company: "test company" - street: ["test street 1", "test street 2"] - city: "test city" - region: "test region" - postcode: "887766" - country_code: "US" - telephone: "88776655" - save_in_address_book: false + firstname: "Bob" + lastname: "Roll" + company: "Magento" + street: ["Magento Pkwy", "Main Street"] + city: "Austin" + region: "TX" + postcode: "78758" + country_code: "US" + telephone: "8675309" + save_in_address_book: False } } } @@ -448,16 +416,16 @@ mutation { "setBillingAddressOnCart": { "cart": { "billing_address": { - "firstname": "test firstname", - "lastname": "test lastname", - "company": "test company", + "firstname": "Bob", + "lastname": "Roll", + "company": "Magento", "street": [ - "test street 1", - "test street 2" + "Magento Pkwy", + "Main Street" ], - "city": "test city", - "postcode": "887766", - "telephone": "88776655" + "city": "Austin", + "postcode": "78758", + "telephone": "8675309" } } } @@ -465,7 +433,7 @@ mutation { } ``` -### Set shipping address on cart +### Set the shipping address on cart Use the `setShippingAddressesOnCart` mutation to set a new shipping address for a specific cart. @@ -483,20 +451,20 @@ The following example creates a new shipping address for a specific cart. mutation { setShippingAddressesOnCart( input: { - cart_id: "OOJVZU6tSSQ8vLoXqx9pDMZili3uQ8Hi" + cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C" shipping_addresses: [ { address: { - firstname: "test firstname" - lastname: "test lastname" - company: "test company" - street: ["test street 1", "test street 2"] - city: "test city" - region: "test region" - postcode: "887766" + firstname: "Bob" + lastname: "Roll" + company: "Magento" + street: ["Magento Pkwy", "Main Street"] + city: "Austin" + region: "TX" + postcode: "78758" country_code: "US" - telephone: "88776655" - save_in_address_book: false + telephone: "8675309" + save_in_address_book: False } } ] From ab5339fdad5c096614a73e231a0cacd53512aba9 Mon Sep 17 00:00:00 2001 From: Erik Marr Date: Sun, 3 Mar 2019 13:51:59 -0600 Subject: [PATCH 5/6] more edits from kevin --- guides/v2.3/graphql/reference/quote.md | 203 ++++++++++++------------- 1 file changed, 101 insertions(+), 102 deletions(-) diff --git a/guides/v2.3/graphql/reference/quote.md b/guides/v2.3/graphql/reference/quote.md index 152f793f52d..ea8bae5809e 100644 --- a/guides/v2.3/graphql/reference/quote.md +++ b/guides/v2.3/graphql/reference/quote.md @@ -119,7 +119,6 @@ The following returns information about a cart given a `cart_id`. Note that the ## Mutations ### Create an empty cart {#createEmptyCart} -{:.no_toc} The `createEmptyCart` mutation creates an empty shopping cart for a guest or logged in customer. If you are creating a cart for a logged in customer, you must include the customer's authorization token in the header of the request. @@ -147,106 +146,7 @@ The response is the quote ID, which is sometimes called the cart ID. The remaini } ``` -### Add and remove coupons from a cart -{:.no_toc} - -You can use mutations to add or remove coupons from a specified cart. - -### Coupon attributes -{:.no_toc} -The add and remove coupon from cart objects can contain the following attributes: - -Attribute | Data Type | Description ---- | --- | --- -`cart_id` | String | The unique ID that identifies the customer's cart -`coupon_code` | String | The coupon code - -### Apply coupon to cart - -Adds a coupon code to a cart. - -#### Syntax - -`mutation: {applyCouponToCart(input: ApplyCouponToCartInput) {ApplyCouponToCartOutput}}` - -#### Example usage - -The following call adds a coupon code called `test2019` to a cart. - -**Request** - -``` text -mutation { - applyCouponToCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C", coupon_code: "test2019"}) { - cart { - applied_coupon { - code - } - } - } -} -``` - -**Response** - -```json -{ - "data": { - "applyCouponToCart": { - "cart": { - "applied_coupon": { - "code": "test2019" - } - } - } - } -} - -``` - -### Remove coupon from cart - -Removes a coupon from the specified cart. - -#### Syntax - -`mutation: {removeCouponFromCart(input: RemoveCouponFromCartInput){ RemoveCouponFromCartOutput}}` - -#### Example usage - -The following example removes a coupon from the cart. - -**Request** - -``` text -mutation { - removeCouponFromCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"}) { - cart { - applied_coupon { - code - } - } - } -} -``` - -**Response** - -```json -{ - "data": { - "removeCouponFromCart": { - "cart": { - "applied_coupon": { - "code": "test2019" - } - } - } - } -} -``` - -### Adding products to cart +### Adding simple products to a cart {:.no_toc} Adds simple items to a specific cart. @@ -433,7 +333,7 @@ mutation { } ``` -### Set the shipping address on cart +### Set the shipping address on a cart Use the `setShippingAddressesOnCart` mutation to set a new shipping address for a specific cart. @@ -493,4 +393,103 @@ mutation { "createEmptyCart": "6XZA7q1ooLEI0jLz8DfFrfruEqgxGzlt" } } +``` + +### Add and remove coupons from a cart +{:.no_toc} + +You can use mutations to add or remove coupons from a specified cart. + +### Coupon attributes +{:.no_toc} +The add and remove coupon from cart objects can contain the following attributes: + +Attribute | Data Type | Description +--- | --- | --- +`cart_id` | String | The unique ID that identifies the customer's cart +`coupon_code` | String | The coupon code + +### Apply coupon to cart + +Adds a coupon code to a cart. + +#### Syntax + +`mutation: {applyCouponToCart(input: ApplyCouponToCartInput) {ApplyCouponToCartOutput}}` + +#### Example usage + +The following call adds a coupon code called `test2019` to a cart. + +**Request** + +``` text +mutation { + applyCouponToCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C", coupon_code: "test2019"}) { + cart { + applied_coupon { + code + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "applyCouponToCart": { + "cart": { + "applied_coupon": { + "code": "test2019" + } + } + } + } +} + +``` + +### Remove coupon from cart + +Removes a coupon from the specified cart. + +#### Syntax + +`mutation: {removeCouponFromCart(input: RemoveCouponFromCartInput){ RemoveCouponFromCartOutput}}` + +#### Example usage + +The following example removes a coupon from the cart. + +**Request** + +``` text +mutation { + removeCouponFromCart(input: {cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"}) { + cart { + applied_coupon { + code + } + } + } +} +``` + +**Response** + +```json +{ + "data": { + "removeCouponFromCart": { + "cart": { + "applied_coupon": { + "code": "test2019" + } + } + } + } +} ``` \ No newline at end of file From 795fefeaa90bdc342fece0c2b169e34d21487b37 Mon Sep 17 00:00:00 2001 From: Erik Marr Date: Sun, 3 Mar 2019 16:48:27 -0600 Subject: [PATCH 6/6] added heading to appear in right nav --- guides/v2.3/graphql/reference/quote.md | 1 - 1 file changed, 1 deletion(-) diff --git a/guides/v2.3/graphql/reference/quote.md b/guides/v2.3/graphql/reference/quote.md index ea8bae5809e..56e50bf0546 100644 --- a/guides/v2.3/graphql/reference/quote.md +++ b/guides/v2.3/graphql/reference/quote.md @@ -147,7 +147,6 @@ The response is the quote ID, which is sometimes called the cart ID. The remaini ``` ### Adding simple products to a cart -{:.no_toc} Adds simple items to a specific cart.