Listening for Smart Cart Events
Below are the events that trigger within the Smart Cart lifecycle. Since the Smart Cart is an extension of the cart object, many of the Cart events can be used to help aid additional functionality such as the 'rebuy:cart.change' event if something needs to be updated conditionally on items that are or are not in the cart.
You are also able to access these events in the form of anonymous function is the Smart Cart settings under the "Advanced" section at the bottom of the settings page. This way there is no need for theme code changes and these functions can be turned on or off with the click of a button.
May developers have used these to provide additional DOM manipulation/creation without the need for a Smart Cart custom template. You can also manipulate the Smart Cart settings if needed as well by adjusting the data within the Smart Cart function
Init
The init event is the first event that is triggered in the Smart Cart lifecycle.
document.addEventListener('rebuy:smartcart.init', (event) => {
console.log('rebuy:smartcart.init event', event.detail);
});
Ready
The "ready" event is triggered once the Smart Cart has fully initialized and everything is ready to run.
document.addEventListener('rebuy:smartcart.ready', (event) => {
const smartcart = event.detail.smartcart;
console.log('rebuy:smartcart.ready: smartcart', smartcart);
});
Show
This event is triggered whenever the show function is called. window.Rebuy.SmartCart.show();
document.addEventListener('rebuy:smartcart.show', (event) => {
const smartcart = event.detail.smartcart;
console.log('rebuy:smartcart.show: smartcart', smartcart);
});
Hide
This event is triggered whenever the hide method is called. window.Rebuy.SmartCart.hide();
document.addEventListener('rebuy:smartcart.hide', (event) => {
const smartcart = event.detail.smartcart;
console.log('rebuy:smartcart.hide: smartcart', smartcart);
});
Item Increase
This event triggers when an items quantity has been increased in the Smart Cart.
document.addEventListener("rebuy:smartcart.line-item-increase", (event) => {
const smartcart = event.detail.smartcart;
const item = event.detail.item;
console.log("rebuy:smartcart.line-item-increase: smartcart", smartcart, item);
});
Item Decrease
This event triggers when an items quantity has been decreased int the Smart Cart.
document.addEventListener("rebuy:smartcart.line-item-decrease", (event) => {
const smartcart = event.detail.smartcart;
const item = event.detail.item;
console.log("rebuy:smartcart.line-item-decrease smartcart", smartcart, item);
});
Item Removed
This event is triggered whenever a customer removes an item from the Smart Cart.
document.addEventListener("rebuy:smartcart.line-item-removed", (event) => {
const smartcart = event.detail.smartcart;
const item = event.detail.item;
console.log("rebuy:smartcart.line-item-removed: smartcart", smartcart, item);
});
Item Switched to Subscription
This event is triggered whenever an item is switched to subscription within the Smart Cart.
document.addEventListener("rebuy:smartcart.item-switch-to-subscription", (event) => {
const smartcart = event.detail.smartcart;
const item = event.detail.item;
console.log("rebuy:smartcart.item-switch-to-subscription, smartcart", smartcart, item);
});
Item Switched to One-time
This event is triggered whenever an item is switched to one-time within the Smart Cart.
document.addEventListener("rebuy:smartcart.item-switch-to-one-time", (event) => {
const smartcart = event.detail.smartcart;
const item = event.detail.item;
console.log("rebuy:smartcart.item-switch-to-one-time, smartcart", smartcart, item);
});
More Cart Listeners
If you're looking to listen for Cart-specific events, please refer to the Cart Event Listeners page for the following event listener options: