- 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 theProductDetailHandler type from @napps/component-extension.
false to cancel the default action when that action supports cancellation.
Formatting PDP Data
UseonFormat to change product information before it is displayed.
draft object lets you edit the visible PDP data:
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:event.data to read the action data.
Example:
Product Detail Context
Product detail handlers receive a context while they are created.- 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.
PDP- Normal Product Detail PageQuickAdd- Quick Add Sheet/DialogSelect- Similar to Quick Add but with the purpose to select a variant
Creation Arguments
When a handler is created, these arguments can be provided:settings for configuration passed to the handler.
Best Practices
- Keep callbacks fast.
- Use
onFormatonly for display formatting. - Use action callbacks for behavior.
- Return
falseonly when you want to stop the default action. - Check optional values before using them.