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

Draft: Reorg GraphQL quote topic #4502

Merged
merged 7 commits into from
May 17, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion _data/toc/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,48 @@ pages:
- label: GroupedProduct endpoint
url: /graphql/reference/grouped-product.html

- label: Quote endpoint
- label: Quote endpoint (cart query)
url: /graphql/reference/quote.html
children:

- label: addSimpleProductsToCart mutation
url: /graphql/reference/quote-add-simple-products.html

- label: addVirtualProductsToCart mutation
url: /graphql/reference/quote-add-virtual-products.html

- label: applyCouponToCart mutation
url: /graphql/reference/quote-apply-coupon.html

- label: createEmptyCart mutation
url: /graphql/reference/quote-create-cart.html

- label: placeOrder mutation
url: /graphql/reference/quote-place-order.html

- label: removeCouponFromCart mutation
url: /graphql/reference/quote-remove-coupon.html

- label: removeItemFromCart mutation
url: /graphql/reference/quote-remove-item.html

- label: setBillingAddressesOnCart mutation
url: /graphql/reference/quote-set-billing-address.html

- label: setGuestEmailOnCart mutation
url: /graphql/reference/quote-set-guest-email.html

- label: setPaymentMethodOnCart mutation
url: /graphql/reference/quote-payment-method.html

- label: setShippingAddressesOnCart mutation
url: /graphql/reference/quote-set-shipping-address.html

- label: setShippingMethodsOnCart mutation
url: /graphql/reference/quote-shipping-method.html

- label: updateCartItems mutation
url: /graphql/reference/quote-update-cart-items.html

- label: Sales endpoint
url: /graphql/reference/sales.html
Expand Down
12 changes: 12 additions & 0 deletions _includes/graphql/cart-address-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Attribute | Data Type | Description
--- | --- | ---
`city` | String! | The city specified for the billing or shipping address
`company` | String | The company specified for the billing or shipping address
`country_code` | String! | The country code and label for the billing or shipping address
`firstname` | String! | The customer's first name
`lastname` | String! | The customer's last name
`postcode` | String | The postal code for the billing or shipping address
`region` | String | The region code and label for the billing or shipping address
`save_in_address_book` | Boolean! | Specifies whether to save the address (`True`/`False`)
`street` | [String]! | An array containing the street for the billing or shipping address
`telephone` | String | The telephone number for the billing or shipping address
4 changes: 4 additions & 0 deletions _includes/graphql/cart-item-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Attribute | Data Type | Description
--- | --- | ---
`quantity` | Float! | The quantity of the item to add to the cart
`sku` | String! | The sku of the product to be added to the cart
18 changes: 18 additions & 0 deletions _includes/graphql/cart-object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Attribute | Data Type | Description
--- | --- | ---
`applied_coupon` | [`AppliedCoupon`][AppliedCoupon] | The `AppliedCoupon` object contains the `code` text attribute, which specifies the coupon code
`available_payment_methods` | [AvailablePaymentMethod][AvailablePaymentMethod] | Available payment methods
`billing_address` | [BillingCartAddress][BillingCartAddress] | Contains the billing address specified in the customer's cart
`email` | String | The customer's email address
`items` | [CartItemInterface][CartItemInterface] | Contains the items in the customer's cart
`prices` | [CartPrices][CartPrices] | Contains subtotals and totals
`selected_payment_method` | [SelectedPaymentMethod][SelectedPaymentMethod] | Selected payment method
`shipping_addresses` | [ShippingCartAddress][ShippingCartAddress] | Contains one or more shipping addresses

[AppliedCoupon]: {{page.baseurl}}/graphql/reference/quote.html#AppliedCoupon
[AvailablePaymentMethod]: {{page.baseurl}}/graphql/reference/quote.html#AvailablePaymentMethod
[BillingCartAddress]: {{page.baseurl}}/graphql/reference/quote.html#BillingCartAddress
[CartItemInterface]: {{page.baseurl}}/graphql/reference/quote.html#CartItemInterface
[CartPrices]: {{page.baseurl}}/graphql/reference/quote.html#CartPrices
[SelectedPaymentMethod]: {{page.baseurl}}/graphql/reference/quote.html#SelectedPaymentMethod
[ShippingCartAddress]: {{page.baseurl}}/graphql/reference/quote.html#ShippingCartAddress
4 changes: 4 additions & 0 deletions _includes/graphql/customizable-option-input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Attribute | Data Type | Description
--- | --- | ---
`id` | Int! | A unique ID assigned to the customizable option
`value_string` | String! | A value assigned to the the customizable option
2 changes: 1 addition & 1 deletion guides/v2.3/graphql/reference/configurable-product.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ Attribute | Type | Description


### Example usage
The following example adds two black Teton Pullover Hoodies size extra-small to the specified shopping cart. The `cart_id` used in this example was [generated]({{ page.baseurl }}/graphql/reference/quote.html#createEmptyCart) by creating an empty cart.
The following example adds two black Teton Pullover Hoodies size extra-small to the specified shopping cart. The `cart_id` used in this example was [generated]({{ page.baseurl }}/graphql/reference/quote-create-cart.html) by creating an empty cart.

**Request**

Expand Down
195 changes: 195 additions & 0 deletions guides/v2.3/graphql/reference/quote-add-simple-products.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
---
group: graphql
title: addSimpleProductsToCart mutation
---

Simple products are physical products that do not have variations, such as color, size, or price. The `addSimpleProductsToCart` mutation allows you to add multiple simple products to the cart at the same time, but you cannot add other product types with this mutation. To add a simple product to a cart, you must provide the cart ID, the SKU, and the quantity. You can also optionally provide customizable options.
keharper marked this conversation as resolved.
Show resolved Hide resolved

{:.bs-callout .bs-callout-info}
The mutation for [adding configurable products]({{page.baseurl}}/graphql/reference/configurable-product.html) is defined in the `ConfigurableProductGraphQl` module.

## Syntax

`mutation: {addSimpleProductsToCart(input: AddSimpleProductsToCartInput): {AddSimpleProductsToCartOutput}}`

## Example usage

These examples show the minimal payload and a payload that includes customizable options.

### Add a simple product to a cart

The following example adds a simple product to a cart. The response contains the entire contents of the customer's cart.

**Request**

```text
mutation {
addSimpleProductsToCart(
input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG",
Copy link
Contributor

Choose a reason for hiding this comment

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

, can be omitted in the request body according to Graphql Docs. It can improve the clearness of the examples.

cart_items: [
{
data: {
quantity: 1
sku: "24-MB04"
}
}
]
}
) {
cart {
items {
id
product {
name
sku
}
quantity
}
}
}
}
```

**Response**

```json
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"id": "13",
"product": {
"name": "Strive Shoulder Pack",
"sku": "24-MB04"
},
"quantity": 1
}
]
}
}
}
}
```

### Add a simple product with customizable options to a cart

If a product has a customizable option, you can specify the option's value in the `addSimpleProductsToCart` request.

**Request**

``` text
mutation {
addSimpleProductsToCart (input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG",
cart_items: {
data: {
sku: "simple"
quantity: 1
},
customizable_options: [
{
id: 121
value_string: "field value"
}
]
}
}) {
cart {
items {
product {
name
}
quantity
... on SimpleCartItem {
customizable_options {
label
values {
value
}
}
}
}
}
}
}
```

**Response**

```text
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"product": {
"name": "simple"
},
"quantity": 1,
"customizable_options": [
{
"label": "Field Option",
"values": [
{
"value": "field value"
}
]
}
]
}
]
}
}
}
}
```

## Input attributes

The top-level `AddSimpleProductsToCartInput` object is listed first. All child objects are listed in alphabetical order.

### AddSimpleProductsToCartInput object {#AddSimpleProductsToCartInput}

The `AddSimpleProductsToCartInput` object must contain the following attributes:

Attribute | Data Type | Description
--- | --- | ---
`cart_id` | String! | The unique ID that identifies the customer's cart
`cart_items` | [SimpleProductCartItemInput!](#SimpleProductCartItemInput) | Contains the cart item IDs and quantity of each item

### CartItemInput object {#CartItemInputSimple}

The `CartItemInput` object must contain the following attributes:

{% include graphql/customizable-option-input.md %}

### CustomizableOptionInput object {#CustomizableOptionInputSimple}

The `CustomizableOptionInput` object must contain the following attributes:

{% include graphql/customizable-option-input.md %}

### SimpleProductCartItemInput object {#SimpleProductCartItemInput}

The `SimpleProductCartItemInput` object must contain the following attributes:

`customizable_options` |[[CustomizableOptionInputSimple]](#CustomizableOptionInputSimple) | An array that defines customizable options for the product
`data` | [CartItemInput!](#CartItemInputSimple) | An object containing the `sku` and `quantity` of the product.

## Output attributes

The `AddSimpleProductsToCartOutput` object contains the `Cart` object.

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

### Cart object {#CartObject}

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

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