The user interface of the configurator is composed of an iframe that communicates via javascript with the page hosting the iframe.
The data exchanged concern:
- Data to initialize the configuration of a product.
- Data regarding prices and availability of the product that you have chosen to initialize.
- Adding the configured product to cart
Iframe code
Add the following code to include the configurator iframe to your system:
<iframe id="zakeke-frame" src="https://portal.zakeke.com/Configurator/index.html" allow="clipboard-read; clipboard-write; fullscreen; web-share"></iframe>
The Zakeke UI is fully responsive, and it's up to you to set the iframe css styling.
Other than adding the iframe code, your system will have to handle the following javascript communication between the Zakeke iframe and hosting page.
The authentication token must include must be of type C2S and you must fill Customer code or Visitor code.
Javascript integration flow with the hosting page
The diagram below will demonstrate the flow of actions from the site visitor going to the site through the process of configuring and adding to cart the product:
Send Zakeke iframe configuration
An object with the property type with "load" as value and the property parameters with the Zakeke iframe configuration object as value has to be sent using postMessage in order to initialize the configurator UI. In order to handle cases where you send the message before the Zakeke code inside the iframe loaded, you must continue to post this message until the iframe post to you a message with type loaded.
It is possible to modify a previously created product configuration ("composition") by passing the property compositionId to the Zakeke iframe configuration object.
Zakeke iframe configuration properties
integrationVersion |
"integrationVersion": 2
The version of the protocol to use for the integration. It must be 2 |
name |
The name of the product. |
token |
A C2S authorization token with a valid customer code or a visitor code. |
ecommerce |
Always set to "api". |
currency |
The three-letter code for the currency used to format the prices. |
culture |
The two letter language code (ISO 639-1). |
modelCode |
The unique numeric identifier for the product to load. |
compositionId |
Optional. Enter in edit for a previously created product configuration. |
qty |
Product quantity to be added to the cart. |
attributes |
The list of attributes and respective values to start the configuration with. Each value is an array of two objects, containing respectively the id of the attribute and the id of the option. |
customAddToCartButtonText |
Optional.
Enter it to change the text of the add to cart button.
|
Code example:
Responding to the price requests
Each time that a product configuration is changed by a customer, Zakeke will ask to the hosting page about the price of that specific product configuration, passing the list of attributes with the respective values chosen and the sum of the unit price for the attributes where the price is managed on the Zakeke side.
The monetary values passed in the request by Zakeke are always in the base currency set in the API settings of your Zakeke account. The response value must be converted in the currency indicated by the "currency" property of the iframe configuration.
Depending on the settings of your system, product, and logged customer, the tax settings must be calculated for the response value.
Depending on the settings of your system, product, and logged customer, the applicable discounts must be calculated for the response value.
Price request properties
zakekeMessageType |
"Price" is used for price requests. |
messageId |
The message identifier that must be present in the response. |
message.compositionPrice |
The sum of all the unit price of the chosen attribute options. |
message.quantity |
Product quantity to be added to the cart. |
message.attributes |
The list of chosen attributes and respective values. For attributes that are linked to attributes on the store, the attributeCode and selectedOptionName properties each contain a json serialized with the sentinel zakekePlatform property and the id of your system. The properties attributeIsEnabled and optionIsEnabled are false if an they didn't pass ythe link check. |
Price response properties
zakekeMessageType |
"Price" is used for price response. |
messageId |
Must be the same messageId of the request. |
message |
An object containing the final price to be shown in the configurator UI and if the selected configuration is out of stock. If the product can't be sold for the requested attributes and quantity, the message the property isOutOfStock must be false. |
Code example:
function handlePriceRequest(request) {
var iframe = document.querySelector("#zakeke-frame");
iframe.contentWindow.postMessage({
messageId: request.messageId,
zakekeMessageType: "Price",
message: {
price: calculateFinalPrice(request.message.attributes,
request.message.quantity,
request.message.compositionPrice),
isOutOfStock: checkStock(request.message.attributes)
}, "*");
}
}
window.addEventListener("message", function (event) {
if (event.data.zakekeMessageType === "Price") {
handlePriceRequest(event.data);
}
}, false);
Add to cart
When the consumer confirms that he wants to purchase the configured product, the Zakeke iframe sends a message to the hosting page containing the composition identifier, a preview image of the product and the requested quantity.
For security reasons, information on the attribute values chosen and the price managed on the Zakeke side must be made via an API S2S request as indicated in the documentation.
Add to cart request properties
zakekeMessageType |
"AddToCart" is used for the add to cart request. |
message.composition |
The identifier to the product configuration. |
message.preview |
Url to image preview of the configured product. |
message.quantity |
Product quantity to be added to the cart. |
Code example:
window.addEventListener("message", function (event) {
if (event.data.zakekeMessageType === "AddToCart") {
handleAddToCartRequest(event.data.message.composition,
event.data.message.preview,
event.data.message.quantity);
}
}, false);