Cart Updated
An event that keeps an eye on cart of the app.
Description
The cartUpdated event triggers whenever the contents of the cart change —
such as when a product is added, removed, or its quantity changes. It provides the updated cart object so you can refresh UI components like cart totals, icons, or badges.
Function Signature
VajroSDK.listeners.onCartUpdated(() => {
// Write your logic
});| Parameter | Type | Required | Description |
|---|---|---|---|
| Nil | Nil | Nil | This listener does not require any parameter. |
Example Usage
let cartTotal = VajroSDK.variables.cart.subtotal || 0;
VajroSDK.listeners.onCartUpdated(() => {
cartTotal = VajroSDK.variables.cart.subtotal || 0;
if (cartTotal > 500) {
VajroSDK.actions.showToast({
title: "Congrats",
message: "You are eligible for Free Shipping!!",
})
}
});Best Practices
- Debounce updates: Avoid flickering by batching UI updates if multiple events fire quickly.
- Always read totals from payload: Avoid caching cart totals to prevent outdated values.
Caveats
- Global event: Fires on any page where the cart changes.
- Frequency: May fire multiple times for a single cart action (e.g., quantity change).
Updated about 1 month ago