Skip to main content

JavaScript API

At runtime the frontend exposes everything through the global window.FPD object. The same object also serves as the input configuration (see Configuration) — the bundle merges its runtime state into whatever your theme defined before load.

Runtime objects

PropertyWhat it is
FPD.instanceThe live FancyProductDesigner instance — the main scripting surface (see below). Exists after the designer was created on a product page.
FPD.productPageThe product page orchestrator (see below).
FPD.CartPageCart page handler (cart page only).
FPD.generalPageAJAX-cart handler (all pages).
FPD.optionsManagerAccess to all resolved options and feature flags.
FPD.taThe resolved theme-abstraction selector tree (product, cart, cartJS, modal).
FPD.shopOptionsThe merged shop options.
FPD.utils{ deepMerge, formatPrice } helpers.
FPD.formatMoneyShopify money formatter.
FPD.funcCallable helpers (see below).

FPD.func.*

FunctionPurpose
FPD.func.fpdDebug()Highlights and logs all theme-abstraction selectors on the page — the fastest way to see whether FPD found your form, button, and container.
FPD.func.updateCartImages()Re-runs cart page thumbnail replacement.
FPD.func.updateCartJSImages()Re-runs AJAX-cart/drawer thumbnail replacement.

FPD.instance — the designer

The designer instance follows the Fancy Product Designer API. The most useful members for integrators:

const fpd = FPD.instance;

fpd.calculatePrice(); // current total customization price
fpd.getElements(); // all elements of the current view
fpd.getCustomElements('all') // elements the customer added
fpd.currentViewInstance // active view (fabricCanvas etc.)
fpd.viewInstances // all views
fpd.loadProduct(productJson) // load an FPD product programmatically

fpd.addEventListener('ready', ...);
fpd.addEventListener('productCreate', ...);
caution

FPD.instance is replaced when the designer is re-initialized (e.g. after certain variant changes). Don't keep long-lived references; re-read FPD.instance or re-attach listeners on productCreate.

FPD.productPage

MemberPurpose
getPluginOption(path)Read any per-product plugin option by path, e.g. getPluginOption('langJSON').
getShopifyProduct()The Shopify product JSON (from #ProductJson-FPD).
getCurrentShopifyVariant()The currently selected variant (from the URL).
getAtcBehavior()'add' or 'update' (update = editing an existing cart line).
updateTa(path, value)Change a theme-abstraction selector at runtime.
reinitializeDesigner()Full designer rebuild — use after your theme morphs the surrounding DOM.
debugTa()Same as FPD.func.fpdDebug().
existingLicThe loaded saved design when the page was opened via an edit link, otherwise unset.

Callbacks (FPD.callbacks)

Callbacks are functions your theme provides before the bundle loads; the frontend invokes them at defined points. This is the supported way to customize flow behavior.

window.FPD = window.FPD || {};
window.FPD.callbacks = {
beforeAddToCart(form) {
// validate; throw to abort the add-to-cart
},
addToCart(addedProduct) {
// after a successful add
},
};

Add-to-cart flow

CallbackSignaturePurpose
beforeAddToCart(form)Runs before the add. Throwing aborts the add-to-cart — use for custom validation.
addToCart(addedProduct)After a successful add.
addProductToForm(form)Replaces the default form.submit() under the submit_form strategy; also called after bulk-order adds with (form, data).
triggerCartDrawer(response)Open your own cart drawer under the trigger_cart_drawer strategy.
cartSections() => string[]Section IDs to request from /cart/add.js (Section Rendering API).

Line item properties

CallbackSignaturePurpose
cartTextPropertiesPost(properties, lineItemCache, shopifyProduct) => propertiesRewrite the line item properties before they are written. Keep all _fpd* keys!
afterSaveCustomization(properties) => propertiesSame, for the save-button flow.

Custom products (LIC)

CallbackSignaturePurpose
onLicCreated(lic, resolve)Intercept after the design was stored; must call resolve() to continue.
newProductName(shopifyProduct, variantId) => stringName for a generated custom product.
extraTags(shopifyProduct, variantId) => tagsExtra tags for a generated custom product.

Page lifecycle & UI

CallbackSignaturePurpose
productPageDone()Product page init finished (designer may still be loading).
afterProductLoaded(fpdProductJSON)The FPD product configuration was loaded.
elementModify(isCustomized)An element changed.
mainImageReplaceCallback(imageEl, previewDataUrl)Customize how the main product image is replaced with the design preview.
cartImageFallback(item, rowEl, images, originalUrl)Take over cart-page thumbnail replacement when the default doesn't fit your markup.
cartJSImageFallback(item, itemEl, image, originalUrl, result) => resultSame for AJAX carts/drawers.
cartAfterUpdate()After a cart update on the cart page.
cartBeforeCheckout()After the checkout button was clicked (best-effort; not guaranteed on all themes).

Other useful globals

  • FPD.additionalPrice — a flat surcharge added to every calculated price (number).
  • FPD.earlyLoadProduct — start loading the product JSON as early as possible.
  • FPD_EXT.productHash — alternative way to hand a saved-design hash to the page (instead of the ?_fpd-hash URL parameter).
  • FPD.debug / FPD.errorReporting — see Troubleshooting.