Skip to content

Cart Data & Events

The Cart drop-in uses the event bus to emit and listen to events for communication between drop-ins and external integrations.

Version: 3.1.0
EventDirectionDescription
cart/initializedEmitsEmitted when the component completes initialization.
cart/product/addedEmitsEmitted when an item is added.
cart/product/removedEmitsEmitted when an item is removed.
cart/product/updatedEmitsEmitted when the component state is updated.
checkout/initializedListensFired by Checkout (checkout) when the component completes initialization.
checkout/updatedListensFired by Checkout (checkout) when the component state is updated.
requisitionList/alertListensFired by Requisition List (requisitionList) when an alert or notification is triggered.
cart/dataEmits and listensTriggered when data is available or changes.
cart/mergedEmits and listensTriggered when data is merged.
cart/resetEmits and listensTriggered when the component state is reset.
cart/updatedEmits and listensTriggered when the component state is updated.
shipping/estimateEmits and listensTriggered when an estimate is calculated.

The following sections provide detailed information about each event, including its direction, event payload, and usage examples.

Emitted when cart data is available or changes. This event is triggered during cart initialization and updates to provide the current cart state.

CartModel | null

See CartModel for full type definition.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/data', (payload) => {
console.log('cart/data event received:', payload);
// Add your custom logic here
});

Emitted when the component completes initialization.

CartModel | null

See CartModel for full type definition.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/initialized', (payload) => {
console.log('cart/initialized event received:', payload);
// Add your custom logic here
});

Emitted when a guest cart is merged with a customer cart after login. This typically happens when an unauthenticated user adds items to their cart, then signs in, and their guest cart items are combined with any existing items in their customer cart.

{
oldCartItems: Item[] | null;
newCart: CartModel | null;
}

See Item, CartModel for full type definitions.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/merged', (payload) => {
console.log('cart/merged event received:', payload);
// Add your custom logic here
});

Emitted when new products are added to the cart. This event fires for genuinely new items, not quantity updates of existing items.

Item[] | null

See Item for full type definition.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/product/added', (payload) => {
console.log('cart/product/added event received:', payload);
// Add your custom logic here
});

Emitted when an item is removed.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/product/removed', (payload) => {
console.log('cart/product/removed event received:', payload);
// Add your custom logic here
});

Emitted when the quantity of existing cart items is increased. This event fires when adding more of a product that’s already in the cart, as opposed to adding a brand new product.

Item[] | null

See Item for full type definition.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/product/updated', (payload) => {
console.log('cart/product/updated event received:', payload);
// Add your custom logic here
});

Triggered when the component state is reset.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/reset', (payload) => {
console.log('cart/reset event received:', payload);
// Add your custom logic here
});

Triggered when the component state is updated.

CartModel | null

See CartModel for full type definition.

import { events } from '@dropins/tools/event-bus.js';
events.on('cart/updated', (payload) => {
console.log('cart/updated event received:', payload);
// Add your custom logic here
});

Fired by Checkout (checkout) when the component completes initialization.

Cart | NegotiableQuote | null

See Cart, NegotiableQuote for full type definitions.

import { events } from '@dropins/tools/event-bus.js';
events.on('checkout/initialized', (payload) => {
console.log('checkout/initialized event received:', payload);
// Add your custom logic here
});

Fired by Checkout (checkout) when the component state is updated.

Cart | NegotiableQuote | null

See Cart, NegotiableQuote for full type definitions.

import { events } from '@dropins/tools/event-bus.js';
events.on('checkout/updated', (payload) => {
console.log('checkout/updated event received:', payload);
// Add your custom logic here
});

Fired by Requisition List (requisitionList) when an alert or notification is triggered.

import { events } from '@dropins/tools/event-bus.js';
events.on('requisitionList/alert', (payload) => {
console.log('requisitionList/alert event received:', payload);
// Add your custom logic here
});

Emitted when shipping cost estimates are calculated for a given address. This event provides both the address used for estimation and the resulting shipping method with its cost.

{
address: PartialAddress;
shippingMethod: ShippingMethod | null;
}

See PartialAddress, ShippingMethod for full type definitions.

import { events } from '@dropins/tools/event-bus.js';
events.on('shipping/estimate', (payload) => {
console.log('shipping/estimate event received:', payload);
// Add your custom logic here
});

The following data models are used in event payloads for this drop-in.

The CartModel represents the complete state of a shopping cart, including items, pricing, discounts, shipping estimates, and gift options.

Used in: cart/data, cart/initialized, cart/merged, cart/updated.

interface CartModel {
totalGiftOptions: {
giftWrappingForItems: Price;
giftWrappingForItemsInclTax: Price;
giftWrappingForOrder: Price;
giftWrappingForOrderInclTax: Price;
printedCard: Price;
printedCardInclTax: Price;
};
cartGiftWrapping: {
uid: string;
design: string;
selected: boolean;
image: WrappingImage;
price: Price;
}[];
giftReceiptIncluded: boolean;
printedCardIncluded: boolean;
giftMessage: {
recipientName: string;
senderName: string;
message: string;
};
appliedGiftCards: AppliedGiftCardProps[];
id: string;
totalQuantity: number;
totalUniqueItems: number;
errors?: ItemError[];
items: Item[];
miniCartMaxItems: Item[];
total: {
includingTax: Price;
excludingTax: Price;
};
discount?: Price;
subtotal: {
excludingTax: Price;
includingTax: Price;
includingDiscountOnly: Price;
};
appliedTaxes: TotalPriceModifier[];
totalTax?: Price;
appliedDiscounts: TotalPriceModifier[];
shipping?: Price;
isVirtual?: boolean;
addresses: {
shipping?: {
countryCode: string;
zipCode?: string;
regionCode?: string;
}[];
};
isGuestCart?: boolean;
hasOutOfStockItems?: boolean;
hasFullyOutOfStockItems?: boolean;
appliedCoupons?: Coupon[];
}

The Item interface represents a single product in the cart, including product details, pricing, quantity, customization options, and inventory status.

Used in: cart/merged, cart/product/added, cart/product/updated.

interface Item {
giftWrappingAvailable: boolean;
giftWrappingPrice: {
currency: string;
value: number;
};
productGiftWrapping: {
uid: string;
design: string;
selected: boolean;
image: WrappingImage;
price: Price;
}[];
giftMessage: {
recipientName: string;
senderName: string;
message: string;
};
priceTiers: PriceTier[];
giftMessageAvailable: boolean | null;
taxedPrice: Price;
rowTotal: Price;
rowTotalIncludingTax: Price;
itemType: string;
uid: string;
url: ItemURL;
canonicalUrl: string;
categories: string[];
quantity: number;
sku: string;
topLevelSku: string;
name: string;
image: ItemImage;
links?: ItemLinks;
price: Price;
total: Price;
discountedTotal?: Price;
discount?: Price;
regularPrice: Price;
discounted: boolean;
bundleOptions?: { [key: string]: any };
bundleOptionsUIDs?: string[];
selectedOptions?: { [key: string]: any };
selectedOptionsUIDs?: { [key: string]: any };
customizableOptions?: { [key: string]: any };
message?: string;
recipient?: string;
recipientEmail?: string;
sender?: string;
senderEmail?: string;
lowInventory?: boolean;
insufficientQuantity?: boolean;
onlyXLeftInStock?: number | null;
outOfStock?: boolean;
notAvailableMessage?: string;
stockLevel?: String;
discountPercentage?: number;
savingsAmount?: Price;
productAttributes?: Attribute[];
fixedProductTaxes?: FixedProductTax[];
}

The PartialAddress interface represents a minimal address used for shipping estimates, containing country, postal code, and region information.

Used in: shipping/estimate.

interface PartialAddress {
countryCode: string;
postCode?: string;
region?: string;
regionCode?: string;
regionId?: number;
}

The ShippingMethod interface represents a shipping option with carrier and method codes, along with pricing information.

Used in: shipping/estimate.

interface ShippingMethod {
carrierCode: string;
methodCode: string;
amountExclTax?: Price;
amountInclTax?: Price;
}