Skip to content

Instantly share code, notes, and snippets.

@basilkhan05
Created March 19, 2026 14:40
Show Gist options
  • Select an option

  • Save basilkhan05/90cf53084923224c7dd6f09aacd92715 to your computer and use it in GitHub Desktop.

Select an option

Save basilkhan05/90cf53084923224c7dd6f09aacd92715 to your computer and use it in GitHub Desktop.
simple-bundles-metafields.liquid
{% comment %}
Simple Bundles Metafield Exposer v5
Handles both:
- Simple Bundles (fixed components) via bundled_variants
- Infinite Options Bundles via bundle_component_selections
{% endcomment %}
<script>
(function() {
window.__SB_VARIANT_METAFIELDS__ = window.__SB_VARIANT_METAFIELDS__ || {};
{% for variant in product.variants %}
{% comment %} Get metafields for both bundle types {% endcomment %}
{% assign bv = variant.metafields.simple_bundles.bundled_variants %}
{% assign io = variant.metafields['app--4901177--simple_bundles']['bundle_component_selections'] %}
{% if bv or io %}
(function() {
var variantId = '{{ variant.id }}';
var simpleComponents = [];
var ioSelections = null;
var bundleType = null;
{% comment %} Check if this is an IO bundle by looking at bundled_variants type {% endcomment %}
{% if bv.value.size > 0 %}
{% assign first_item = bv.value | first %}
{% if first_item.type == 'Infinite options' %}
bundleType = 'infinite_options';
{% else %}
bundleType = 'simple';
{% endif %}
{% endif %}
{% comment %} For Simple Bundles: extract components from bundled_variants {% endcomment %}
{% if bv.value.size > 0 %}
{% for item in bv.value %}
{% if item.type != 'Infinite options' %}
simpleComponents.push([{{ item.variant_id }}, {{ item.quantity_in_bundle | default: 1 }}]);
{% endif %}
{% endfor %}
{% endif %}
{% comment %} For IO Bundles: extract the selection mapping {% endcomment %}
{% if io.value %}
ioSelections = {{ io.value | json }};
{% endif %}
window.__SB_VARIANT_METAFIELDS__[variantId] = {
simple_bundle_components: simpleComponents.length > 0 ? simpleComponents : null,
bundle_component_selections: ioSelections,
bundle_type: bundleType
};
console.log('[SB-Metafields] Variant', variantId, '- Type:', bundleType,
bundleType === 'simple' ? '- Components:' + simpleComponents.length : '- IO Selections loaded');
})();
{% endif %}
{% endfor %}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment