Embeb Printcart Designer to your web application with our simple JS SDK.
npm
npm install @printcart/design-tool-sdkyarn
yarn add @printcart/design-tool-sdkunpkg
<script src="https://unpkg.com/@printcart/design-tool-sdk"></script>
Using package:
import PrintcartDesigner from "@printcart/design-tool-sdk";
const designer = new PrintcartDesigner({
token: "your-printcart-unauth-token",
productId: "your-product-id",
options: {},
});Using CDN-hosted copy of the library:
<script src="https://unpkg.com/@printcart/design-tool-sdk/dist/main.js"></script>
<script>
const designer = new PrintcartDesigner({
token: "your-printcart-unauth-token",
productId: "your-product-id",
options: {},
});
</script>- Required
- Type:
string
Your Printcart Unauth Token. You can get your token from your Printcart Dashboard.
- Required
- Type:
string
The Product ID that you want to assign the designer to.
- Optional
- Type:
object | undefined
Provide options to config the Designer UI and locale.
Parameters
processBtnBgColor: string | null - Change the Process button background color.logoUrl: string | null - Add your branding logo to Designer.variantId: string | undefined - Open the Designer on this store variant (sent asvariant_id; the Designer loads the variant's print sides). Since 1.7.0.selectedChoices: object | undefined - The buyer's picked option choices, e.g.{ Wood: "Walnut" }(passed with the Designer settings). Since 1.7.0.locale: string | undefined - Buyer UI language, e.g."en","fr"or"fr-CA"(sent aslocale; falls back to the browser language). Since 1.7.0.
Render and display Designer.
Example
const designer = new PrintcartDesigner({
token: "your-printcart-unauth-token",
productId: "your-product-id",
});
var openDesignerButton = document.getElementById("your-button-id");
openDesignerButton.addEventListener("click", function () {
designer.open();
});Switch an open Designer to another variant without reloading it (for example when the buyer changes a colour or size on the product page). The next render() / editDesign() also opens on that variant. Since 1.7.0.
Example
designer.setVariant("variant-id", { Wood: "Cherry" });Unmount and hide Designer.
Example
designer.close();Subscribe to an Designer event. See below for full list of events.
Example
designer.on("upload-success", callback);Exposed events that you can subscribe in your app:
Fired when Designer finish render and displayed to the screen.
Example
designer.on("rendered", function () {
console.log("Designer opened.");
});Fired when Designer closed.
Example
designer.on("closed", function () {
console.log("Designer closed.");
});Fired when Designer fully loaded.
Example
designer.on("render-finish", function () {
console.log("Designer rendered.");
});Parameters:
response- Printcart API Response object for design upload.
Fired when all upload success.
Example
designer.on("upload-success", function (response) {
console.log("Response:", response);
});Parameters:
error- The error object from Printcart API Response.
Example
designer.on("upload-error", function (error) {
console.log(error);
});Parameters:
response- Printcart API Response object for design edit.
Example
designer.on("edit-success", function (response) {
console.log("Response:", response);
});Fired when Designer enter edit mode.
Example
designer.on("edit", function () {
console.log("Designer on edit mode");
});
