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) => {
const smartcart = event.detail.smartcart;
console.log('rebuy:smartcart.init: smartcart', smartcart);
});
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);
});
Remove
This event is triggered whenever a customer removes a product from the Smart Cart.
document.addEventListener('rebuy:smartcart.product-removed', (event) => {
const smartcart = event.detail.smartcart;
console.log('rebuy:smartcart.product-removed: smartcart', smartcart);
});
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: