addBundleProductsToCart mutation

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 by creating an empty 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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:

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
  "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!] An array of bundle items to add to the cart

BundleProductCartItemInput object

The BundleProductCartItemInput object contains the following attributes:

Attribute Type Description
bundle_options [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] An object that contains the ID and value of the product
data CartItemInput! An object that contains the quantity and SKU of the bundle product

BundleOptionInput object

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

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

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

Output attributes

The AddBundleProductsToCartOutput 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

Cart query output provides more information about the Cart object.