Ga naar inhoud

JavaScript helpers

Deze inhoud is nog niet vertaald.

A bundle page exposes a few global functions for custom templates built in Template Creator. They’re available once the bundle has loaded.

window.BundleBuilder.canAddVariant(variantId, sectionIndex)

Whether a variant can be added to the bundle right now, taking the bundle’s limits and the variant’s available quantity into account.

Parameter Type Description
variantId string The Shopify variant ID.
sectionIndex string The index of the section the variant is in, from 0.

Returns boolean. Logs an error and returns false if there is no section at sectionIndex.

if (window.BundleBuilder.canAddVariant('44012345678901', '0')) {
// show the add button
}
window.BundleBuilder.showMoreModal(variantId, sectionIndex, canSelectVariant, canAdd)

Opens the Read more dialog for a variant, with all of its product’s images and its description.

Parameter Type Description
variantId number The variant to show.
sectionIndex number The index of the section the variant is in, from 0.
canSelectVariant boolean, optional false hides the variant pickers. Defaults to true.
canAdd boolean, optional false hides the add button. Defaults to true.
<img
src="{{ product.featured_image | image_url: width: 400 }}"
onclick="window.BundleBuilder.showMoreModal({{ variant.id }}, {{ forloop.index0 }})"
>
window.BundleBuilder.srcset(url)

A srcset attribute value for an image on Shopify’s CDN, at the widths Kitenzo uses. Returns an empty string for any other URL.

img.srcset = window.BundleBuilder.srcset(img.src);

By default, adding a bundle to the cart sends the shopper to the cart page. Define window.bbAfterAddToCart to do something else instead, for example open your theme’s cart drawer.

Bundle page template
<script>
window.bbAfterAddToCart = function () {
// Open your theme's cart drawer here.
// Return { offerReplace: false } to skip the replace offer.
};
</script>
Return value What happens
Nothing The shopper stays on the page, and Kitenzo offers to replace the bundle if they edit it.
{ offerReplace: false } The shopper stays on the page, and the bundle page behaves as a plain add to cart.

To react to an add without changing where the shopper goes, listen for the kitenzo:addtocart:complete event instead. It fires on document after every successful add, before any redirect.

document.addEventListener('kitenzo:addtocart:complete', () => {
// e.g. update a cart count in your header
});