Methods reference
Bu içerik henüz dilinizde mevcut değil.
Methods are called directly on the element (const tg = document.getElementById('tg')).
Synchronous reads
Section titled “Synchronous reads”Instant, served from the cached last selection_change. Return null / [] until the
first event arrives.
getSelection()
Section titled “getSelection()”Current configuration:
{ parts: [{ partId, partLabel, variantId, label, sku, modelName }], shareUrl }.
getSkus()
Section titled “getSkus()”The SKUs of the current configuration, one per configurable part — the cart payload:
["OSLO-BODY-WALNUT", "OSLO-LEGS-CHROME"].
getShareUrl()
Section titled “getShareUrl()”Deep-link URL that rebuilds the current configuration exactly. Persist it on the order line — it is the one field worth storing beyond the SKUs.
Configuration
Section titled “Configuration”Async — each returns a Promise.
getOptions()
Section titled “getOptions()”Enumerate every part + all its variants with select()-ready handles. Resolves to
[{ partId, partKey, label, defaultVariantId, variants: [{ variantId, handle, label, sku, swatch, swatchImage, modelName, isDefault, available }] }].
select(partKey, variantKey)
Section titled “select(partKey, variantKey)”Drive a selection from your own UI. Keys are the URL handles (select('body', 'walnut')).
Resolves with { ok, selection } after the model swap settles; rejects on unknown
handle or timeout.
reset()
Section titled “reset()”Back to the published default. Resolves with { ok, selection }.
Commerce sync
Section titled “Commerce sync”setAvailability(map)
Section titled “setAvailability(map)”Push live stock: setAvailability({ body: { walnut: false } }) — keys are the same handles
getOptions() returns; false = out of stock. Out-of-stock swatches dim, strike through
and become unselectable in the built-in picker; getOptions() then reports each variant’s
available. Resolves with { ok, applied }.
setPrices(prices)
Section titled “setPrices(prices)”Push price display from your catalogue:
tg.setPrices({ currency: 'EUR', locale: 'de-DE', items: { 'SKU-1': 129.9 }, total: 259.8 });Keys are the same SKUs the events report. Numbers are Intl-formatted with
currency/locale; strings are shown verbatim; total is optional (auto-summed when
every shown price is numeric). Prices appear in the viewer’s summary. Pass null to clear.
Resolves with { ok, applied }.
Camera & AR
Section titled “Camera & AR”resetCamera()
Section titled “resetCamera()”Ease the camera back to its opening framing. Resolves with { ok }.
enterAR()
Section titled “enterAR()”Launch AR (iOS Quick Look / Android Scene Viewer / WebXR). Call from your own click
handler — WebXR may require an in-page user gesture. Resolves with { ok }.
Sharing & capture
Section titled “Sharing & capture”getSnapshot()
Section titled “getSnapshot()”PNG data-URL of the currently-configured model (the summary hero image). Resolves
{ ok, url } — best-effort, ok: false when capture is unavailable.
getShareLink()
Section titled “getShareLink()”Short device-adaptive share link (…/s/{code}) for the current configuration — the same
link the built-in summary’s Share box and QR encode. Resolves { ok, url } (falls back to
the full launcher URL).
getQr(params?)
Section titled “getQr(params?)”QR PNG data-URL for the desktop “scan to view in AR” flow. Defaults to the short share
link; pass { text, size } to encode something else. Resolves { ok, url }.
Timing
Section titled “Timing”Async methods can be called before the viewer is ready — requests queue and flush once the viewer’s bridge is up. Default timeout: 30 s.
