Event Listeners
These events provide access to the Rebuy Cart module. Rebuy keeps a copy of the Shopify cart, so cart add and cart change events trigger even when changes happen outside of Rebuy features. For example, if a customer adds an item from the product details page, the add event will still trigger.
Accessing cart data
The cart property in event.detail is the Rebuy Cart module, not the Shopify cart directly. Access the Shopify cart data via cart.cart:
document.addEventListener('rebuy:cart.change', (event) => {
const { cart } = event.detail;
console.log(cart.cart.total_price); // Shopify cart data
});
Ready
Triggers when the cart object is ready.
document.addEventListener('rebuy:cart.ready', (event) => {
const { cart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
cart |
object |
The Rebuy Cart module (access Shopify cart via cart.cart) |
Add
Triggers when an item is added to the cart.
document.addEventListener('rebuy:cart.add', (event) => {
const { cart, item } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
cart |
object |
The Rebuy Cart module (access Shopify cart via cart.cart) |
item |
object |
The item that was added, or an object with items array and sections when multiple items are added (e.g., {items: [...], sections: {...}}) |
Change
Triggers when the cart changes (add, remove, quantity increase, quantity decrease).
document.addEventListener('rebuy:cart.change', (event) => {
const { cart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
cart |
object |
The Rebuy Cart module (access Shopify cart via cart.cart) |
Enriched
Triggers when the cart is enriched with additional subscription information.
document.addEventListener('rebuy:cart.enriched', (event) => {
const { cart } = event.detail;
// Your logic here
});
Payload
| Property |
Type |
Description |
cart |
object |
The Rebuy Cart module with enriched subscription data (access Shopify cart via cart.cart) |
---
title: Event Listeners
excerpt: Listen for cart ready, add, change, and enriched events
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: ''
---
These events provide access to the Rebuy Cart module. Rebuy keeps a copy of the Shopify cart, so cart add and cart change events trigger even when changes happen outside of Rebuy features. For example, if a customer adds an item from the product details page, the add event will still trigger.
!!! note "Accessing cart data"
The `cart` property in `event.detail` is the Rebuy Cart module, not the Shopify cart directly. Access the Shopify cart data via `cart.cart`:
```javascript
document.addEventListener('rebuy:cart.change', (event) => {
const { cart } = event.detail;
console.log(cart.cart.total_price); // Shopify cart data
});
```
## Ready
Triggers when the cart object is ready.
```javascript
document.addEventListener('rebuy:cart.ready', (event) => {
const { cart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `cart` | object | The Rebuy Cart module (access Shopify cart via `cart.cart`) |
## Add
Triggers when an item is added to the cart.
```javascript
document.addEventListener('rebuy:cart.add', (event) => {
const { cart, item } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `cart` | object | The Rebuy Cart module (access Shopify cart via `cart.cart`) |
| `item` | object | The item that was added, or an object with `items` array and `sections` when multiple items are added (e.g., `{items: [...], sections: {...}}`) |
## Change
Triggers when the cart changes (add, remove, quantity increase, quantity decrease).
```javascript
document.addEventListener('rebuy:cart.change', (event) => {
const { cart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `cart` | object | The Rebuy Cart module (access Shopify cart via `cart.cart`) |
## Enriched
Triggers when the cart is enriched with additional subscription information.
```javascript
document.addEventListener('rebuy:cart.enriched', (event) => {
const { cart } = event.detail;
// Your logic here
});
```
### Payload
| Property | Type | Description |
|----------|------|-------------|
| `cart` | object | The Rebuy Cart module with enriched subscription data (access Shopify cart via `cart.cart`) |
## Related
- [Smart Cart Event Listeners](smart-cart-event-listeners.md) - Events for the Smart Cart UI
- [Widget Event Listeners](widget-event-listeners.md) - Events for recommendation widgets