Adding to Cart from the Customizer
This guide explains how to integrate the VU Customizer with a storefront’s shopping cart.
The integration has two main responsibilities:
VU Customizer: Validates and saves the recipe, returning recipe and cart metadata.
Storefront / client integration: Takes the returned recipe information and adds the configured product to its own shopping cart.
The recommended approach is to use the Customizer’s addToCart() method and listen for the customizer.add-to-cart event. An alternative is to save the recipe directly using saveRecipe(true).
Typical user flow looks like the below:
The user configures a product in the VU Customizer.
The user then clicks the customizers Add to Cart button.
The Customizer validates and saves the recipe.
The Customizer returns recipe and cart metadata.
The storefront integration uses the returned data to add the configured product to its own cart.
The Customizer does not automatically add the returned data to every storefront’s cart. The client-side integration must handle that step.
Customizer Events to complete the ATC:
A. Add to Cart completed
The customizer.add-to-cart event fires when the recipe has been saved.
Use the following listener to inspect the event:
document.addEventListener("customizer.add-to-cart", (event) => {
console.log("ATC completed:", event);
});The event detail contains information used by the client’s cart integration. The source documentation identifies the following data as available:
Recipe body
Images
SKU
Recipe token
B. Monitor the complete lifecycle
The Customizer also provides events for earlier stages of the Add to Cart process.
These events allow you to inspect the process in sequence:
customizer.add-to-cart-clicked— The shopper clicked Add to Cart.customizer.before-add-to-cart— The process reached the stage before the recipe is saved.customizer.add-to-cart— The recipe has been saved.
C. Save the recipe directly
If the storefront owns the Add to Cart button and you want to avoid the Customizer Add to Cart event flow, you can save the recipe directly using window.customizer.saveRecipe(true).
This approach returns the recipe data directly to your client-side code.
Example implementation
How this approach works
The storefront calls
window.customizer.saveRecipe(true).The Customizer saves the recipe.
The returned response is stored in
response.The recipe and cart data are extracted from
response.data.The storefront integration passes that data to its own cart implementation.
As in the previous example, clientCart.add(cartData) is a placeholder for the storefront’s actual cart-add function.
When to use this approach
Use direct saving when you want your storefront to own the button interaction and manage the recipe-saving call directly.
The original documentation identifies this as an alternative. The preferred public event flow remains addToCart() combined with the customizer.add-to-cart listener.
Last updated