Skip to main content
The Product Detail Handler Extension lets you customize behavior on the product detail page. Use this extension when you want to format PDP data or control product actions through callbacks. You can use it to:
  • Change product information before it is shown.
  • Add, remove, or replace product tags.
  • Change the displayed title, vendor, SKU, stamp image, or availability.
  • React when the selected product or variant changes.
  • React when the user adds a product to the cart.
  • React when the user clicks product, quick add, collection, vendor, or external navigation actions.
  • Cancel supported default actions by returning false.

Handler Shape

The extension is based on the ProductDetailHandler type from @napps/component-extension.
Callbacks can be synchronous or asynchronous. If the callback is async, the app will only wait up to 3 seconds before assuming the callback failed.
When a callback receives an event, you can return false to cancel the default action when that action supports cancellation.

Formatting PDP Data

Use onFormat to change product information before it is displayed.
The draft object lets you edit the visible PDP data:
The same draft exposes read-only gallery media and lets you attach tags to individual images and videos.
Media cannot be reordered, hidden, or added. addMediaTag replaces an existing tag with the same ID on the same media item. A tag must contain text, an icon URL, or both. onFormat runs again when the selected variant or option changes, and the entire formatting hook shares the three-second timeout. Example:

Action Callbacks

The handler can react to PDP actions through optional callbacks.

onDestroyed

Runs when the handler is destroyed. Use it to clean up work you started inside the handler.

onFormat

Runs when PDP display data can be formatted. Use it to change title, vendor, SKU, availability, stamp image, low stock information, or tags.

onVariantSelected

Runs when a variant is selected.

onProductSelected

Runs when a product is selected. The event data contains:

onAddedToCart

Runs when a product is added to the cart. The event data contains:

onProductClicked

Runs when a product is clicked. The event data contains:

onProductQuickAddClicked

Runs when the quick add action is clicked for a product. The event data contains the clicked product.

onExternalNavigationRequestClicked

Runs when an external navigation action is clicked. The event data contains:

onCollectionClicked

Runs when a collection action is clicked. The event data contains:

onVendorClicked

Runs when a vendor action is clicked. The event data contains:

Event Object

Callbacks that receive an event use this shape:
Use event.data to read the action data. Example:

Product Detail Context

Product detail handlers receive a context while they are created.
The context lets you:
  • Read the current product ID.
  • Read the current product, when available.
  • Read the selected variant, when available.
  • Check how the product detail flow is being used.
  • Ask the user to select a variant.
  • Select a variant by ID.
  • Select an option by type and value.
The handling type can be:
  • PDP - Normal Product Detail Page
  • QuickAdd - Quick Add Sheet/Dialog
  • Select - Similar to Quick Add but with the purpose to select a variant

Creation Arguments

When a handler is created, these arguments can be provided:
Use settings for configuration passed to the handler.

Best Practices

  • Keep callbacks fast.
  • Use onFormat only for display formatting.
  • Use action callbacks for behavior.
  • Return false only when you want to stop the default action.
  • Check optional values before using them.