addSimpleProductsToCart mutation
The addSimpleProductsToCart
mutation allows you to add any number of simple and group products to the cart at the same time.
Simple products are physical products that do not have variations, such as color, size, or price. Group products are a set of simple standalone products that are assigned a unique SKU and are presented as a group. Each product in the group is purchased as a separate item.
To add a simple or grouped product to a cart, you must provide the cart ID, the SKU, and the quantity. You can also optionally provide customizable options.
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mutation {
addSimpleProductsToCart(
input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
cart_items: [
{
data: {
quantity: 1
sku: "24-MB04"
}
}
]
}
) {
cart {
items {
id
product {
name
sku
}
quantity
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"product": {
"name": "simple"
},
"quantity": 1,
"customizable_options": [
{
"label": "Field Option",
"values": [
{
"value": "field value"
}
]
}
]
}
]
}
}
}
}
Add a grouped product to a cart
The following example adds a grouped product (Workout-Kit
) to a cart. The grouped product contains three simple products.
Request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
mutation {
addSimpleProductsToCart(
input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
cart_items: [
{
data: {
quantity: 1
sku: "Workout-Kit"
}
}
]
}
) {
cart {
items {
id
product {
name
sku
}
quantity
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
"data": {
"addSimpleProductsToCart": {
"cart": {
"items": [
{
"id": "5",
"product": {
"name": "Go-Get'r Pushup Grips",
"sku": "24-UG05"
},
"quantity": 1
},
{
"id": "6",
"product": {
"name": "Dual Handle Cardio Ball",
"sku": "24-UG07"
},
"quantity": 1
},
{
"id": "7",
"product": {
"name": "Harmony Lumaflex™ Strength Band Kit ",
"sku": "24-UG03"
},
"quantity": 1
}
]
}
}
}
}
Input attributes
The top-level AddSimpleProductsToCartInput
object is listed first. All child objects are listed in alphabetical order.
AddSimpleProductsToCartInput object
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! | Contains the cart item IDs and quantity of each item |
CartItemInput object
The CartItemInput
object must contain the following attributes:
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 |
CustomizableOptionInput object
The CustomizableOptionInput
object must contain the following attributes:
Attribute | Data Type | Description |
---|---|---|
id |
Int! | A unique ID assigned to the customizable option |
value_string |
String! | A value assigned to the customizable option |
SimpleProductCartItemInput object
The SimpleProductCartItemInput
object must contain the following attributes:
customizable_options |
[CustomizableOptionInputSimple] | An array that defines customizable options for the product |
data |
CartItemInput! | 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! | Describes the contents of the specified shopping cart |
Cart object
Attribute | Data Type | Description |
---|---|---|
applied_coupon |
AppliedCoupon |
Deprecated. Use applied_coupons instead |
applied_coupons |
[AppliedCoupon ] |
An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code |
applied_gift_cards |
[AppliedGiftCard ] |
An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module |
applied_store_credit |
AppliedStoreCredit |
Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module |
available_payment_methods |
[AvailablePaymentMethod] | Available payment methods |
billing_address |
BillingCartAddress | Contains the billing address specified in the customer’s cart |
email |
String | The customer’s email address |
id |
ID! | The ID of the cart |
is_virtual |
Boolean! | Indicates whether the cart contains only virtual products |
items |
[CartItemInterface] | Contains the items in the customer’s cart |
prices |
CartPrices | Contains subtotals and totals |
selected_payment_method |
SelectedPaymentMethod | Selected payment method |
shipping_addresses |
[ShippingCartAddress]! | Contains one or more shipping addresses |
total_quantity |
Float! | Total Quantity of products in the cart |
Cart query output provides more information about the Cart
object.
Errors
Error | Description |
---|---|
Could not find a cart with ID "XXX" |
The specified cart_id value does not exist in the quote_id_mask table. |
Could not find a product with SKU "YYY" |
A simple product with the SKU specified in the data .sku argument does not exist. |
Required parameter "cart_id" is missing |
The cart_id argument was omitted or contains an empty value. |
Required parameter "cart_items" is missing |
The cart_items argument was omitted or contains an empty value. |
The current user cannot perform operations on cart XXX |
An unauthorized user (guest) tried to add the product into a customer’s cart, or an authorized user (customer) tried to add the product into the cart of another customer. |
The product's required option(s) weren't entered. Make sure the options are entered and try again. |
A simple product has customizable options that were not specified in the mutation, but are required for adding the product into the cart. |