To implement bundling using the cart_transform function in this sample app, you must configure specific metafields on product variants to define the relationship between a 'parent' bundle variant and its 'child' component variants.
1. Configure Variant Metafield Definitions
Create the following three metafield definitions under Settings > Custom data > Variants:
| Name | Namespace and key | Type |
|---|
component_reference | custom.component_reference | Product Variant (List of product variants) |
component_quantities | custom.component_quantities | Integer (List of values, Min: 1) |
component_parents | custom.component_parents | JSON |
JSON Schema for custom.component_parents:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Bundle component parents",
"description": "A definition of the bundle a child belongs to",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"description": "ID of bundle parent product variant: gid://shopify/ProductVariant/<id number>",
"type": "string"
},
"component_reference": {
"type": "object",
"properties": {
"value": {
"description": "Array of product variant IDs: [gid://shopify/ProductVariant/<id number>]",
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
},
"required": ["value"]
},
"component_quantities": {
"type": "object",
"properties": {
"value": {
"description": "Array of quantities of product variants defined in component_reference: [1]",
"type": "array",
"items": {
"type": "integer"
},
"minItems": 1
}
},
"required": ["value"]
},
"price_adjustment": {
"type": "object",
"properties": {
"value": {
"description": "Array of quantities of product variants defined in component_reference: [1]",
"type": "array",
"items": {
"type": "number",
"minimum": 0
}
}
},
"required": ["value"]
}
},
"required": ["id", "component_reference", "component_quantities"]
}
}
2. Define the Bundle Parent
- Create a product to act as the bundle. It must have at least one variant in inventory, a price > 0, and at least one option.
- On the Parent Product Variant page, locate the
Metafields section. - Set
custom.component_reference by selecting the product variants that will be included in the bundle. - Set
custom.component_quantities by entering quantities that correspond to the order of variants in component_reference. - Note the Parent Variant ID from the browser URL (e.g.,
gid://shopify/ProductVariant/<id>).
3. Define the Bundle on Child Variants
For each child variant included in the bundle, you must update its custom.component_parents metafield with a JSON array matching the parent's configuration:
[
{
"id": "gid://shopify/ProductVariant/<ID of parent product variant>",
"component_reference": {
"value": [
"gid://shopify/ProductVariant/<ID of first child product variant>",
"gid://shopify/ProductVariant/<ID of second child product variant>"
]
},
"component_quantities": {
"value": [
<quantity of first product variant in bundle>,
<quantity of second product variant in bundle>
]
}
}
]