Skip to main content

Overview

Product components handle product display, variant selection, inventory management, and add-to-cart functionality.

ProductFormComponent

Manages the main product form with add-to-cart functionality, variant tracking, and quantity validation.

Class Definition

Refs

HTMLInputElement
required
Hidden input containing the selected variant ID
AddToCartComponent
Container for the add-to-cart button
HTMLElement
Error message display element
HTMLElement
Container for Shop Pay and other accelerated checkout buttons
HTMLElement
required
ARIA live region for screen reader announcements
HTMLElement
Label showing quantity already in cart
HTMLElement
B2B quantity rules display
HTMLElement
Container for form buttons and quantity selector
HTMLElement
B2B volume pricing component
QuantitySelectorComponent
Quantity selector component instance
HTMLElement
Wrapper around quantity selector
HTMLElement
Label for quantity selector
HTMLElement
B2B price-per-item display

Methods

handleSubmit()

Handles form submission and add-to-cart action.
product-form.js
Validation:
product-form.js

Events

The component orchestrates multiple event types: Listens:
  • ThemeEvents.variantUpdate - Updates form when variant changes
  • ThemeEvents.variantSelected - Marks variant change as in progress
  • ThemeEvents.cartUpdate - Syncs quantity selector with cart state
Dispatches:
  • CartAddEvent - When item is added to cart
  • CartErrorEvent - When add-to-cart fails

Variant Change Handling

product-form.js

Example


AddToCartComponent

Manages the add-to-cart button with animations and visual feedback.

Class Definition

Refs

HTMLButtonElement
required
The add-to-cart button element

Methods

disable()

Disables the add-to-cart button.
product-form.js

enable()

Enables the add-to-cart button.
product-form.js

handleClick()

Handles button click with optional fly-to-cart animation.
product-form.js

animateAddToCart()

Animates the button state change (“Add to Cart” → “Added”).
product-form.js

Data Attributes

boolean
Enable fly-to-cart animation
string
URL of product image for fly-to-cart animation

Example


QuantitySelectorComponent

Quantity input with increment/decrement buttons and validation.

Class Definition

Refs

HTMLInputElement
required
The number input element
HTMLButtonElement
required
Decrement button
HTMLButtonElement
required
Increment button

Methods

getValue() / setValue()

Get or set the current quantity value.
component-quantity-selector.js

updateConstraints()

Updates min/max/step and snaps value to valid increment.
component-quantity-selector.js

getCurrentValues()

Reads current constraints and value from DOM.
component-quantity-selector.js

getEffectiveMax()

Calculates maximum quantity that can be added.
component-quantity-selector.js

canAddToCart()

Validates if current quantity can be added to cart.
component-quantity-selector.js

setCartQuantity()

Updates the cart quantity and refreshes button states.
component-quantity-selector.js

increaseQuantity() / decreaseQuantity()

Increment or decrement the quantity.
component-quantity-selector.js

Events

Dispatches:
  • QuantitySelectorUpdateEvent - When quantity changes
component-quantity-selector.js

Example


VariantPicker

Manages product variant selection with option pickers.

Class Definition

Refs

HTMLFieldSetElement[]
Array of fieldset elements containing variant options

Methods

variantChanged()

Handles variant option selection.
variant-picker.js

fetchUpdatedSection()

Fetches variant HTML and updates the page.
variant-picker.js

Properties

HTMLInputElement | HTMLOptionElement
Currently selected variant option element
string[]
Array of all selected option value IDs

Events

Listens:
  • change - Variant option changed
Dispatches:
  • VariantSelectedEvent - When option is selected
  • VariantUpdateEvent - After variant data is fetched

Example


ProductPrice

Dynamic price display that updates when variants change.

Class Definition

Refs

HTMLElement
required
Container for price display
HTMLElement
B2B volume pricing note

Methods

updatePrice()

Updates price display when variant changes.
product-price.js

Example


ProductInventory

Displays product inventory levels that update with variant changes.

Class Definition

Methods

updateInventory()

Updates inventory display when variant changes.
product-inventory.js

Example