Introduction
Viewer embeds communicate with the host page through postMessage. The current runtime starts with a nonce handshake, then requests an embed token using ALTER_TOOL_INIT_SESSION.
Setup:
- In the Alter Product app, open the E-commerce Settings Embeding panel.
- Add the domain where the Viewer will be embedded (for example https://yourwebsite.com or http://localhost:3000) and save.
Flow:
- Your website loads the Viewer iframe.
- The iframe sends
ALTER_CHILD_HELLO; your page answers withALTER_PARENT_ACKand the same nonce. - The iframe requests a token with
ALTER_TOOL_INIT_SESSIONandpayload.toolset toviewer. - Your backend creates the token through Alter Product Public API, and your page responds with
ALTER_TOOL_SESSION_READY. - With
add_to_cart=1, the Viewer can emitALTER_VIEWER_ADD_TO_CART. The host can also request the current payload withALTER_VIEWER_GET_PRODUCT_DATAand receiveALTER_VIEWER_DATA_RESPONSE.
Variant metadata configured in Product Configuration is included in the payload.