Skip to content

Commit

Permalink
Issue #1049 [graphql documentation] addBundleProductsToCart mutation (#…
Browse files Browse the repository at this point in the history
…5947)

* Issue #1049 [graphql documentation] addBundleProductsToCart mutation, add link to a list of topics

* Issue #1049 [graphql documentation] addBundleProductsToCart mutation. Fix linting test errors.

* Update add-bundle-products.md

Updated for grammar, alphabetizing, and  consistency with other topics.

* Update add-bundle-products.md

Adding contributor info
  • Loading branch information
karyna-t authored and keharper committed Nov 6, 2019
1 parent bb1c29f commit 38a8a08
Show file tree
Hide file tree
Showing 2 changed files with 243 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _data/toc/graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pages:
- label: Using mutations
url: /graphql/mutations/index.html

- label: addBundleProductsToCart mutation
url: /graphql/mutations/add-bundle-products.html

- label: addConfigurableProductsToCart mutation
url: /graphql/mutations/add-configurable-products.html

Expand Down
240 changes: 240 additions & 0 deletions guides/v2.3/graphql/mutations/add-bundle-products.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
---
group: graphql
title: addBundleProductsToCart mutation
contributor_name: Atwix
contributor_link: https://www.atwix.com/
---

Use the `addBundleProductsToCart` mutation to add bundle products to a specific cart.

## Syntax

`mutation: {addBundleProductsToCart(input: AddBundleProductsToCartInput): {AddBundleProductsToCartOutput}}`

## Example usage

The following example uses a bundle product "Sprite Yoga Companion Kit" from Magento sample data.
The SKU of this product is: **24-WG080**

This example adds one bundle product with following children to the specified shopping cart:

- Sprite Stasis Ball 65 cm (x1)
- Sprite Foam Yoga Brick (x2)
- Sprite Yoga Strap 10 foot (x1)
- Sprite Foam Roller (x1)

The `cart_id` used in this example was [generated]({{ page.baseurl }}/graphql/mutations/create-empty-cart.html) by creating an empty cart.

**Request**

```graphql
mutation {
addBundleProductsToCart(
input: {
cart_id: "wARFaDnHva0tgzuforUYR4rvXincj5eu"
cart_items: [
{
data: {
sku: "24-WG080"
quantity: 1
}
bundle_options: [
{
id: 1
quantity: 1
value: [
"2"
]
},
{
id: 2
quantity: 2
value: [
"4"
]
},
{
id: 3
quantity: 1
value: [
"7"
]
},
{
id: 4
quantity: 1
value: [
"8"
]
}
]
},
]
}) {
cart {
items {
id
quantity
product {
sku
}
... on BundleCartItem {
bundle_options {
id
label
type
values {
id
label
price
quantity
}
}
}
}
}
}
}
```

**Response**

```json
{
"data": {
"addBundleProductsToCart": {
"cart": {
"items": [
{
"id": "7",
"quantity": 1,
"product": {
"sku": "24-WG080"
},
"bundle_options": [
{
"id": 1,
"label": "Sprite Stasis Ball",
"type": "radio",
"values": [
{
"id": 2,
"label": "Sprite Stasis Ball 65 cm",
"price": 27,
"quantity": 1
}
]
},
{
"id": 2,
"label": "Sprite Foam Yoga Brick",
"type": "radio",
"values": [
{
"id": 4,
"label": "Sprite Foam Yoga Brick",
"price": 5,
"quantity": 2
}
]
},
{
"id": 3,
"label": "Sprite Yoga Strap",
"type": "radio",
"values": [
{
"id": 7,
"label": "Sprite Yoga Strap 10 foot",
"price": 21,
"quantity": 1
}
]
},
{
"id": 4,
"label": "Sprite Foam Roller",
"type": "radio",
"values": [
{
"id": 8,
"label": "Sprite Foam Roller",
"price": 19,
"quantity": 1
}
]
}
]
}
]
}
}
}
}
```

## Input attributes

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

### AddBundleProductsToCartInput object

The `AddBundleProductsToCartInput` object contains the following attributes:

Attribute | Type | Description
--- | --- | ---
`cart_id` | String! | The unique ID that identifies the customer's cart
`cart_items` | [[BundleProductCartItemInput!]](#bundleProductCartItemInput) | An array of bundle items to add to the cart

### BundleProductCartItemInput object {#bundleProductCartItemInput}

The `BundleProductCartItemInput` object contains the following attributes:

Attribute | Type | Description
--- | --- | ---
`bundle_options` | [[BundleOptionInput!]](#bundleOptionInput) | An object that contains an array of options of the bundle product with the chosen value and quantity of each option
`customizable_options` | [[CustomizableOptionInput]](#customOptionInput) | An object that contains the ID and value of the product
`data` | [CartItemInput!](#cartItemInput) | An object that contains the quantity and SKU of the bundle product

### BundleOptionInput object {#bundleOptionInput}

The `BundleOptionInput` object contains the following attributes:

Attribute | Type | Description
--- | --- | ---
`id` | Int! | ID of the option
`quantity` | Float! | The number of a specific child item to add to the cart
`value` | [String!]! | An array with the chosen value of the option

### CartItemInput object {#cartItemInput}

The `CartItemInput` object contains the following attributes:

Attribute | Type | Description
--- | --- | ---
`quantity` | Float! | The number of items to add to the cart
`sku` | String! | The SKU of the product

### CustomizableOptionInput object {#customOptionInput}

The `CustomizableOptionInput` object must contain the following attributes:

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

## Output attributes

The `AddBundleProductsToCartOutput` 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/queries/cart.html#cart-output) provides more information about the `Cart` object.

## Related topics

- [Bundle product data types]({{page.baseurl}}/graphql/product/bundle-product.html)

0 comments on commit 38a8a08

Please sign in to comment.