Event Listeners
These events trigger within the Smart Cart lifecycle. Since Smart Cart extends the cart object, Cart events like rebuy:cart.change can also be used for cart-based logic.
You can also add these as anonymous functions in Smart Cart settings under the "Advanced" section—no theme code changes required.
Init
Triggers when the Smart Cart begins initialization.
document.addEventListener('rebuy:smartcart.init', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Ready
Triggers when the Smart Cart has fully initialized and is ready.
document.addEventListener('rebuy:smartcart.ready', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Show
Triggers when the Smart Cart is shown. Can also be triggered via window.Rebuy.SmartCart.show().
document.addEventListener('rebuy:smartcart.show', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Hide
Triggers when the Smart Cart is hidden. Can also be triggered via window.Rebuy.SmartCart.hide().
document.addEventListener('rebuy:smartcart.hide', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
Item Increase
Triggers when an item's quantity is increased in the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-increase', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was increased |
Item Decrease
Triggers when an item's quantity is decreased in the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-decrease', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was decreased |
Item Removed
Triggers when a customer removes an item from the Smart Cart.
document.addEventListener('rebuy:smartcart.line-item-removed', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was removed |
Item Switched to Subscription
Triggers when an item is switched to subscription within the Smart Cart.
document.addEventListener('rebuy:smartcart.item-switch-to-subscription', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was switched |
Item Switched to One-time
Triggers when an item is switched to one-time purchase within the Smart Cart.
document.addEventListener('rebuy:smartcart.item-switch-to-one-time', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
smartcart |
object |
The Smart Cart instance |
item |
object |
The cart item that was switched |
---
title: Event Listeners
excerpt: Handle cart lifecycle events and trigger custom logic with JavaScript
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: ''
---
These events trigger within the Smart Cart lifecycle. Since Smart Cart extends the cart object, [Cart events](cart-event-listeners.md) like `rebuy:cart.change` can also be used for cart-based logic.
You can also add these as anonymous functions in Smart Cart settings under the "Advanced" section—no theme code changes required.
## Init
Triggers when the Smart Cart begins initialization.
```javascript
document.addEventListener('rebuy:smartcart.init', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Ready
Triggers when the Smart Cart has fully initialized and is ready.
```javascript
document.addEventListener('rebuy:smartcart.ready', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Show
Triggers when the Smart Cart is shown. Can also be triggered via `window.Rebuy.SmartCart.show()`.
```javascript
document.addEventListener('rebuy:smartcart.show', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Hide
Triggers when the Smart Cart is hidden. Can also be triggered via `window.Rebuy.SmartCart.hide()`.
```javascript
document.addEventListener('rebuy:smartcart.hide', (event) => {
const { smartcart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
## Item Increase
Triggers when an item's quantity is increased in the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-increase', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was increased |
## Item Decrease
Triggers when an item's quantity is decreased in the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-decrease', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was decreased |
## Item Removed
Triggers when a customer removes an item from the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.line-item-removed', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was removed |
## Item Switched to Subscription
Triggers when an item is switched to subscription within the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.item-switch-to-subscription', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was switched |
## Item Switched to One-time
Triggers when an item is switched to one-time purchase within the Smart Cart.
```javascript
document.addEventListener('rebuy:smartcart.item-switch-to-one-time', (event) => {
const { smartcart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `smartcart` | object | The Smart Cart instance |
| `item` | object | The cart item that was switched |
## Related
- [Cart Event Listeners](cart-event-listeners.md) - Events for the underlying cart object
- [Widget Event Listeners](widget-event-listeners.md) - Events for recommendation widgets