Skip to content
Kitenzo Headless is currently invite-only. To enable it on your store, email support@kitenzo.com.

Vanilla — createBundleEmbed

createBundleEmbed (from @kitenzo/core) renders the full admin-configured bundle UI into a container element and handles script loading, settings fetching and add-to-cart interception. Use it in plain JS or any non-React framework.

import { createBundleEmbed } from '@kitenzo/core';
const embed = createBundleEmbed(document.getElementById('bundle-root')!, {
bundleId: 42,
apiKey: 'kit_live_…',
shopDomain: 'my-store.myshopify.com',
onAddToCart: ({ lines, bundleContent }) => {
// 1. Add cart lines via the Storefront API
cart.linesAdd(lines);
// 2. For native bundles, write the `_bundles` cart attribute
if (bundleContent) {
const existing = JSON.parse(
cart.attributes?.find((a) => a.key === '_bundles')?.value ?? '{}'
);
existing[bundleContent.configuredBundleId] = bundleContent;
cart.cartAttributesUpdate([
...(cart.attributes ?? []).filter((a) => a.key !== '_bundles'),
{ key: '_bundles', value: JSON.stringify(existing) },
]);
}
},
});
// Later, to tear it down:
embed.destroy();
OptionTypeRequiredDescription
bundleIdnumberYesBundle to display.
apiKeystringYesHeadless API key.
shopDomainstringYesYour myshopify.com domain.
onAddToCart(payload: EmbedCartPayload) => voidYesCalled when the customer adds to cart.
onError(error: Error) => voidNoCalled on script/settings load failure.
baseUrlstringNoOverride the API base URL.
scriptUrlstringNoOverride the storefront script URL (derived from baseUrl by default).

Returns a BundleEmbedInstance with a single method: destroy() — removes the embed from the DOM and cleans up listeners.

interface EmbedCartPayload {
lines: CartLine[];
bundleContent?: BundleContentPayload; // native bundles only
}
interface BundleContentPayload {
id: number;
configuredBundleId: number;
title: string;
discount: string; // encrypted discount string for the cart transform
image: string | null;
note?: { text: string; label: string };
items: Array<{ variantId: number; count: number }>;
}