How To Add Bundle Products in Cart By Using GraphQL in Magento 2.x / Adobe Commerce 2.x

The following below steps need to follow to add Bundle products by using GraphQL in Magento 2.x

Use the updateCartItems mutation to update shopping cart items and removeItemFromCart to remove a product from the shopping cart.

Step [1] – Recommendation to use below Bundle Product syntax

Here Using Postman

Syntax –

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

Step [2] – Put below Request

mutation {
  addBundleProductsToCart(
    input: {
      cart_id: "SUAzreA0RsakaL5YcNC2rmgYjfscCZZC"
      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
          name
        }
        ... on BundleCartItem {
          bundle_options {
            id
            label
            type
            values {
              id
              label
              price
              quantity
            }
          }
        }
      }
    }
  }
}

Step [3] – Below output response

{
    "data": {
        "addBundleProductsToCart": {
            "cart": {
                "items": [
                    {
                        "id": "132",
                        "quantity": 14,
                        "product": {
                            "sku": "24-WG080",
                            "name": "Sprite Yoga Companion Kit"
                        },
                        "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
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "id": "137",
                        "quantity": 6,
                        "product": {
                            "sku": "MH01",
                            "name": "Chaz Kangeroo Hoodie"
                        }
                    }
                ]
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *