This is an advanced customization. We recommend enlisting the help of a developer if you need assistance in implementing this functionality.
Custom JavaScript can be used to hook into existing theme functionality without touching theme code. This page serves as a reference for all the custom events Primavera exposes.
A custom event can be fired by instantiating an instance of the custom event, and then dispatching it.
const event = new CustomEvent('dialog:trigger:cart-drawer');
document.dispatchEvent(event);
You can listen to an event listener by listening to it on the document element, just like any other event.
All the dialogs in the theme are triggered by the same set of core events.
You can open or close a dialog manually, or listen for existing open close events by replacing the [name] text with the name of the dialog. The name of the dialog can be found in the data-name attribute. So for example, in the following snippet, the name is 'cart-drawer'.
document.addEventListener('variant:change', (event) => {
// The event detail includes the section id,
// the full rendered HTML from the section rendering API, and the variant object
const { sectionId, html, variant } = event.detail;
});
Cart
This event fires when the shopping cart is updated.
document.addEventListener('cart:change', (event) => {
// The event detail includes the source of the change ('product-form' by default),
// the variant id, and the cart response as JSON.
const { source, productVariantId, cartData } = event.detail;
});
This event fires when there is a shopping cart error after an fetch event.
document.addEventListener('cart:error', (event) => {
// The event detail includes the source of the change ('product-form' by default),
// the variant id, the response.errors object and an optional message.
const { source, productVariantId, errors, message } = event.detail;
});