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

Commit 38a8a08

Browse files
karyna-tkeharper
authored andcommitted
Issue #1049 [graphql documentation] addBundleProductsToCart mutation (#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
1 parent bb1c29f commit 38a8a08

File tree

2 files changed

+243
-0
lines changed

2 files changed

+243
-0
lines changed

_data/toc/graphql.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ pages:
121121
- label: Using mutations
122122
url: /graphql/mutations/index.html
123123

124+
- label: addBundleProductsToCart mutation
125+
url: /graphql/mutations/add-bundle-products.html
126+
124127
- label: addConfigurableProductsToCart mutation
125128
url: /graphql/mutations/add-configurable-products.html
126129

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
---
2+
group: graphql
3+
title: addBundleProductsToCart mutation
4+
contributor_name: Atwix
5+
contributor_link: https://www.atwix.com/
6+
---
7+
8+
Use the `addBundleProductsToCart` mutation to add bundle products to a specific cart.
9+
10+
## Syntax
11+
12+
`mutation: {addBundleProductsToCart(input: AddBundleProductsToCartInput): {AddBundleProductsToCartOutput}}`
13+
14+
## Example usage
15+
16+
The following example uses a bundle product "Sprite Yoga Companion Kit" from Magento sample data.
17+
The SKU of this product is: **24-WG080**
18+
19+
This example adds one bundle product with following children to the specified shopping cart:
20+
21+
- Sprite Stasis Ball 65 cm (x1)
22+
- Sprite Foam Yoga Brick (x2)
23+
- Sprite Yoga Strap 10 foot (x1)
24+
- Sprite Foam Roller (x1)
25+
26+
The `cart_id` used in this example was [generated]({{ page.baseurl }}/graphql/mutations/create-empty-cart.html) by creating an empty cart.
27+
28+
**Request**
29+
30+
```graphql
31+
mutation {
32+
addBundleProductsToCart(
33+
input: {
34+
cart_id: "wARFaDnHva0tgzuforUYR4rvXincj5eu"
35+
cart_items: [
36+
{
37+
data: {
38+
sku: "24-WG080"
39+
quantity: 1
40+
}
41+
bundle_options: [
42+
{
43+
id: 1
44+
quantity: 1
45+
value: [
46+
"2"
47+
]
48+
},
49+
{
50+
id: 2
51+
quantity: 2
52+
value: [
53+
"4"
54+
]
55+
},
56+
{
57+
id: 3
58+
quantity: 1
59+
value: [
60+
"7"
61+
]
62+
},
63+
{
64+
id: 4
65+
quantity: 1
66+
value: [
67+
"8"
68+
]
69+
}
70+
]
71+
},
72+
]
73+
}) {
74+
cart {
75+
items {
76+
id
77+
quantity
78+
product {
79+
sku
80+
}
81+
... on BundleCartItem {
82+
bundle_options {
83+
id
84+
label
85+
type
86+
values {
87+
id
88+
label
89+
price
90+
quantity
91+
}
92+
}
93+
}
94+
}
95+
}
96+
}
97+
}
98+
```
99+
100+
**Response**
101+
102+
```json
103+
{
104+
"data": {
105+
"addBundleProductsToCart": {
106+
"cart": {
107+
"items": [
108+
{
109+
"id": "7",
110+
"quantity": 1,
111+
"product": {
112+
"sku": "24-WG080"
113+
},
114+
"bundle_options": [
115+
{
116+
"id": 1,
117+
"label": "Sprite Stasis Ball",
118+
"type": "radio",
119+
"values": [
120+
{
121+
"id": 2,
122+
"label": "Sprite Stasis Ball 65 cm",
123+
"price": 27,
124+
"quantity": 1
125+
}
126+
]
127+
},
128+
{
129+
"id": 2,
130+
"label": "Sprite Foam Yoga Brick",
131+
"type": "radio",
132+
"values": [
133+
{
134+
"id": 4,
135+
"label": "Sprite Foam Yoga Brick",
136+
"price": 5,
137+
"quantity": 2
138+
}
139+
]
140+
},
141+
{
142+
"id": 3,
143+
"label": "Sprite Yoga Strap",
144+
"type": "radio",
145+
"values": [
146+
{
147+
"id": 7,
148+
"label": "Sprite Yoga Strap 10 foot",
149+
"price": 21,
150+
"quantity": 1
151+
}
152+
]
153+
},
154+
{
155+
"id": 4,
156+
"label": "Sprite Foam Roller",
157+
"type": "radio",
158+
"values": [
159+
{
160+
"id": 8,
161+
"label": "Sprite Foam Roller",
162+
"price": 19,
163+
"quantity": 1
164+
}
165+
]
166+
}
167+
]
168+
}
169+
]
170+
}
171+
}
172+
}
173+
}
174+
```
175+
176+
## Input attributes
177+
178+
The top-level `AddBundleProductsToCartInput` object is listed first. All interfaces and child objects are listed in alphabetical order.
179+
180+
### AddBundleProductsToCartInput object
181+
182+
The `AddBundleProductsToCartInput` object contains the following attributes:
183+
184+
Attribute | Type | Description
185+
--- | --- | ---
186+
`cart_id` | String! | The unique ID that identifies the customer's cart
187+
`cart_items` | [[BundleProductCartItemInput!]](#bundleProductCartItemInput) | An array of bundle items to add to the cart
188+
189+
### BundleProductCartItemInput object {#bundleProductCartItemInput}
190+
191+
The `BundleProductCartItemInput` object contains the following attributes:
192+
193+
Attribute | Type | Description
194+
--- | --- | ---
195+
`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
196+
`customizable_options` | [[CustomizableOptionInput]](#customOptionInput) | An object that contains the ID and value of the product
197+
`data` | [CartItemInput!](#cartItemInput) | An object that contains the quantity and SKU of the bundle product
198+
199+
### BundleOptionInput object {#bundleOptionInput}
200+
201+
The `BundleOptionInput` object contains the following attributes:
202+
203+
Attribute | Type | Description
204+
--- | --- | ---
205+
`id` | Int! | ID of the option
206+
`quantity` | Float! | The number of a specific child item to add to the cart
207+
`value` | [String!]! | An array with the chosen value of the option
208+
209+
### CartItemInput object {#cartItemInput}
210+
211+
The `CartItemInput` object contains the following attributes:
212+
213+
Attribute | Type | Description
214+
--- | --- | ---
215+
`quantity` | Float! | The number of items to add to the cart
216+
`sku` | String! | The SKU of the product
217+
218+
### CustomizableOptionInput object {#customOptionInput}
219+
220+
The `CustomizableOptionInput` object must contain the following attributes:
221+
222+
{% include graphql/customizable-option-input.md %}
223+
224+
## Output attributes
225+
226+
The `AddBundleProductsToCartOutput` object contains the `Cart` object.
227+
228+
Attribute | Data Type | Description
229+
--- | --- | ---
230+
`cart` |[Cart!](#CartObject) | Describes the contents of the specified shopping cart
231+
232+
### Cart object {#CartObject}
233+
234+
{% include graphql/cart-object.md %}
235+
236+
[Cart query output]({{page.baseurl}}/graphql/queries/cart.html#cart-output) provides more information about the `Cart` object.
237+
238+
## Related topics
239+
240+
- [Bundle product data types]({{page.baseurl}}/graphql/product/bundle-product.html)

0 commit comments

Comments
 (0)