Skip to main content

Add a variant fixed bundle

A variant fixed bundle is a bundle that's configured at the variant level. This guide shows you how to add a variant fixed bundle using the productVariantRelationshipBulkUpdate mutation.


In this tutorial, you'll learn how to do the following tasks:

  • Use the GraphQL Admin API to create a product with variants
  • Associate components to variants
  • Delete components in a bundle


A variant fixed bundle is modeled as a variant associated with other component variants using the productVariantComponents relationship.

The bundle parent variant's price determines the price, while the inventory of each component's variants determines the bundle inventory. This is the same for product fixed bundles.

A variant has a productVariantComponents field that determines the bundles' components. Two bundle variants can have the same components.

A diagram showing the relationship between product variants that model a bundle

The following diagram shows an example of a product variant ("The Hair and Skin Bundle") that models a bundle and contains two components: "Natural Shampoo 50 ml" and "Coconut Conditioner". The bundle is modeled by creating a variant, associating the variant with components, and assigning a quantity of one to each component.

A diagram showing a bundle example with two components

Anchor to Limitations and considerationsLimitations and considerations

  • A bundle can have up to 30 components.
  • After an app has assigned components to a bundle, only that app can manage the components of the bundle.
  • Nested bundles aren't supported. A bundle can't have components and be part of another bundle simultaneously.

Anchor to Step 1: Create a product with variantsStep 1: Create a product with variants

To create a product with variants, you can run the productCreate mutation.

The following example creates a product with a single variant modelling a bundle.

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL query

mutation CreateProductBundle($input: ProductInput!) {
productCreate(input: $input) {
product {
title
variants(first: 10) {
edges{
node{
id
price
}
}
}
}
userErrors{
field
message
}
}
}

Variables

{
"input": {
"title": "The Hair And Skin Bundle",
"variants": [
{
"price": 10
}
]
}
}

JSON response

{
"data": {
"productCreate": {
"product": {
"title": "The Hair And Skin Bundle",
"variants": {
"edges": [
{
"node": {
"id": "gid://shopify/ProductVariant/PRODUCT-VARIANT-ID",
"price": "10.00"
}
}
]
}
},
"userErrors": []
}
}
}

Anchor to Step 2: Associate components to variantsStep 2: Associate components to variants

After creating the product variant, you need to associate the components of a bundle. To do that, you can run the productVariantRelationshipBulkUpdate mutation.

If the variant is associated with components, then the attribute productVariant.requiresComponents returns true.

The following example associates two components, a Shampoo variant and a Soap variant, with a quantity of one to the product variant created in the previous step.

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

GraphQL query

mutation CreateBundleComponents($input: [ProductVariantRelationshipUpdateInput!]!) {
productVariantRelationshipBulkUpdate(input: $input) {
parentProductVariants {
id
productVariantComponents(first: 10) {
nodes{
id
quantity
productVariant {
id
}
}
}
}
userErrors {
code
field
message
}
}
}

Variables

{
"input": [{
"parentProductVariantId": "gid://shopify/ProductVariant/PRODUCT-VARIANT-ID",
"productVariantRelationshipsToCreate": [
{
"id": "gid://shopify/ProductVariant/SHAMPOO-PRODUCT-VARIANT-ID-COMPONENT-1",
"quantity": 1
},
{
"id": "gid://shopify/ProductVariant/SOAP-PRODUCT-VARIANT-ID-COMPONENT-2",
"quantity": 1
}
]
}]
}

JSON response

{
"data": {
"productVariantRelationshipBulkUpdate": {
"parentProductVariants": [
{
"id": "gid://shopify/ProductVariant/PRODUCT-VARIANT-ID",
"productVariantComponents": {
"nodes": [
{
"id": "gid://shopify/ProductVariantComponent/PRODUCT_VARIANT_COMPONENT_1",
"productVariant": {
"id": "gid://shopify/ProductVariant/SHAMPOO-PRODUCT-VARIANT-ID-COMPONENT-1"
}
},
{
"id": "gid://shopify/ProductVariantComponent/PRODUCT_VARIANT_COMPONENT_2",
"productVariant": {
"id": "gid://shopify/ProductVariant/SOAP-PRODUCT-VARIANT-ID-COMPONENT-2"
}
}
]
}
}
],
"userErrors": []
}
}
}
Tip

If you need to remove components from a bundle, you can run the productVariantRelationshipBulkUpdate mutation with productVariantRelationshipsToRemove input.



Was this page helpful?