Skip to main content

Live Demo

Open this store (password: bundles)

This page has the following script which adds a bundle with contents added on behalf of the customer https://currantapp.myshopify.com/pages/bundle-sdk-demo

Under the hood it is adding a selection for the small box variant here https://currantapp.myshopify.com/products/byo-meal-box

<button id="addToCart">Add to cart</button>
<script src="https://static.rechargecdn.com/assets/storefront/recharge-client-1.3.0.min.js"></script>
<script>
document.getElementById('addToCart').addEventListener('click', async () => {
const variantId = '41291293425861';
const selection = {
externalVariantId: variantId,
externalProductId: '7134322196677',
selections: [
{
collectionId: '285790863557', // collection1
externalProductId: '7200062308549',
externalVariantId: '41504991412421', // this product must exist in collection1
quantity: 2,
},
{
collectionId: '288157827269', // collection2
externalProductId: '7200061391045',
externalVariantId: '41510929465541', // this product must exist in collection2
quantity: 2,
},
],
};

recharge.init({
// this should be your myshopifyUrl
storeIdentifier: 'currantapp.myshopify.com',
// this should be your Recharge Storefront Access Token
storefrontAccessToken: 'storefrontAccessToken',
});

console.log({ bundleConfiguration: await recharge.cdn.getCDNBundleSettings(7134322196677) });

const _rb_id = await recharge.bundle.getBundleId(selection, {});

const data = {
items: [
{
id: variantId,
quantity: 1,
selling_plan: 743178437,
properties: {
_rb_id, // this is the only require attribute - which links the bundle to this particular line item
},
},
],
};

await fetch(window.Shopify.routes.root + 'cart/add.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

window.location.href = '/cart';
});
</script>