Skip to main content

Overview

Cart components handle all cart-related functionality including displaying items, updating quantities, managing discounts, and showing cart state.

CartItemsComponent

Displays and manages cart items with real-time updates.

Class Definition

Refs

HTMLElement[]
Array of quantity selector elements for each cart item
HTMLTableRowElement[]
Array of cart item row elements
TextComponent
Element displaying the cart total

Methods

updateQuantity()

Updates the quantity of a cart line item.
number
required
Line item number (1-indexed)
number
required
New quantity value
string
required
Action type: 'change' or 'clear'
component-cart-items.js
Usage:

onLineItemRemove()

Removes a line item from the cart with animation.
component-cart-items.js

Events

The component listens for and dispatches cart-related events: Listens:
  • ThemeEvents.cartUpdate - Updates from other cart components
  • ThemeEvents.discountUpdate - Discount code changes
  • ThemeEvents.quantitySelectorUpdate - Quantity changes from selectors
Dispatches:
  • CartUpdateEvent - When cart is successfully updated

Properties

string
The Shopify section ID for this cart component
boolean
Whether this component is used in a drawer

Example


CartQuantitySelectorComponent

Quantity selector specialized for cart contexts, using absolute maximum values.

Class Definition

Methods

getEffectiveMax()

Returns the absolute maximum allowed in cart (not adjusted for current cart quantity).
component-cart-quantity-selector.js

updateButtonStates()

Updates plus/minus button states based on current value and limits.
component-cart-quantity-selector.js

Usage


CartDrawerComponent

Manages the slide-out cart drawer with history integration.

Class Definition

Refs

HTMLDialogElement
required
The native dialog element

Methods

open()

Opens the cart drawer and manages installments dialog.
cart-drawer.js

close()

Closes the cart drawer.
cart-drawer.js

Features

History Integration:
  • Pushes history state when opened on mobile
  • Closes on back button press
  • Cleans up history state on close
Sticky Summary:
  • Automatically calculates if cart summary should stick to bottom
  • Based on summary height vs drawer height ratio
Auto-open:
  • Opens automatically when items are added (if auto-open attribute is set)

Events

Listens:
  • CartAddEvent - Auto-opens if configured
  • DialogOpenEvent - Updates sticky state and manages history
  • DialogCloseEvent - Cleans up history state

Example


CartIcon

Displays cart icon with animated item count bubble.

Class Definition

Refs

HTMLElement
required
The cart count bubble element
HTMLElement
required
Text inside the bubble
HTMLElement
required
Element displaying the count number

Methods

renderCartBubble()

Updates the cart count with animation.
number
required
Total items in cart
boolean
required
If true, increments current count; if false, sets absolute count
boolean
default:"true"
Whether to animate the change
cart-icon.js

ensureCartBubbleIsCorrect()

Validates cart count against sessionStorage on page load.
cart-icon.js

Properties

number
Current cart item count

Events

Listens:
  • ThemeEvents.cartUpdate - Updates count when cart changes
  • pageshow - Validates count when page restored from cache

Example


CartNote

Manages customer cart note with debounced updates.

Class Definition

Methods

updateCartNote()

Debounced handler for cart note updates (200ms delay).
cart-note.js

Example


CartDiscount

Manages discount code application and removal.

Class Definition

Refs

HTMLElement
required
General error message container
HTMLElement
required
Invalid discount code error message
HTMLElement
required
Shipping discount error message

Methods

applyDiscount()

Applies a discount code to the cart.
cart-discount.js

removeDiscount()

Removes a discount code from the cart.
cart-discount.js

Events

Dispatches:
  • DiscountUpdateEvent - When discount is applied or removed

Example