API Methods
Available methods
getProductAttributes
Get available attributes on a product. The client can then apply/change these attributes using setProductAttribute() method.
window.expivi.getProductAttributes().then(function(productAttributes){
console.log('available attributes: ', productAttributes);
});
Attribute Object Structure
Property | Description | Type |
---|---|---|
id | Attribute’s ID to be used to set Attribute. | number |
name | Attribute's name. | string |
type | Type of the attribute (e.g., question, matgroup, text_input, etc). | string |
slug | (Optional) Attribute's slug. | string |
hash | (Optional) Unique hash. | string |
description | Description of the attribute. | string |
position | Position of the attribute in the rendered list. | number |
thumbnail | Thumbnail file. | string |
thumbnail_url | Complete URL of the thumbnail. | string |
parent_id | Attribute's parent ID [nullable]. | number |
meta | Metadata represented as meta. | any |
visibility | Whether the attribute is visible during initialization. | number |
global | Indicates if the attribute is global (used by more products). | boolean |
attribute_values | (Optional) Available values, polymorphic based on type. | AttributeValueInterface[] |
entity_properties | (Optional) Assigned entity properties on attribute. | EntityPropertyInterface[] |
selected_value_id | (Optional) Currently selected attribute value ID (term). | number |
selected_value_value | (Optional) Currently selected value. | any |
visible | (Optional) Visibility changed by rules system. | boolean |
setProductAttribute
Set/change an attribute’s value on product.
window.expivi.setProductAttribute(aAttributeId : number, aValue : any);
Parameter Descriptions
Parameter | Description | Type |
---|---|---|
aAttributeId | The ID of the attribute to change its value. | number |
aValue | The value to set for the attribute, based on its type. | Depends on attribute's type |
Possible Values for aValue
Based on Attribute’s Type
Attribute Type | Description | Expected Value Type |
---|---|---|
question | Attribute value's ID. | number |
matgroup | Material reference's ID. | number |
text_input | Text to be set on input. | string |
text_to_image | Text to be set. | string |
image_upload | URL of the uploaded image. | string |
color_picker | Hex code of the selected color. | string (hex code) |
color | Hex code of the selected color. | string (hex code) |
setProductAttributeNamed
Set/Change an attribute’s value on product.
window.expivi.setProductAttribute(aAttributeName : string, aValue : any);
Parameter Descriptions
Parameter | Description | Type |
---|---|---|
aAttributeName | The name of the attribute to change its value. | string |
aValue | The value to set for the attribute, based on its type. | Depends on attribute's type |
The provided value (aValue
) should correspond to the attribute’s type.
Refer to the setProductAttribute
documentation for details on expected values based on the attribute type.
getActiveMaterial
Get the actively selected reference id of material inside a material group.
window.expivi.getActiveMaterial(aMaterialGroupId : number, aProductSceneId? : string) : Promise<number>;
Parameter Descriptions
Return a promise containing the active reference ID.
Parameter | Description | Type |
---|---|---|
aMaterialGroupId | The ID of the material group. | number |
aProductSceneId | (Optional) The unique product ID containing the material group (resolved from window.expivi.resolveProductNodes() ). | number |
setActiveMaterial
Sets or selects the active material within a material group using its material reference ID.
window.expivi.setActiveMaterial(aMaterialGroupId : number, aReferenceId : number, aProductSceneId? : string) : Promise<number>;
Parameter Descriptions
Return a promise containing the selected reference ID.
Parameter | Description | Type |
---|---|---|
aMaterialGroupId | The ID of a material group. | number |
aReferenceId | The reference ID of the material inside the material group - see resolveMaterialGroups | number |
aProductSceneId | (Optional) The unique product ID containing the material group (resolved from window.expivi.resolveProductNodes() ). | string |
getScreenshot
window.expivi.getScreenshot(aWidth : number, aHeight : number) : Promise<string>;
Parameter Descriptions
Return a promise containing a string with Base64 Image data.
Parameter | Description | Type | Default |
---|---|---|---|
aWidth | (Optional) The width of the screenshot. | number | 512 |
aHeight | (Optional) The height of the screenshot. | number | 512 |
getPrice
Calculate and return the total price of a product.
window.expivi.getPrice(aProductSceneId? : string) : Promise<number>;
Parameter Description
Return a promise containing a numeric value of the calculated price.
Parameter | Description | Type | Default |
---|---|---|---|
aProductSceneId | (Optional) The unique product id to get its price (resolved from window.expivi.resolveProductNodes() ). | string | null |
setNodeProperty
Set/change an internal property of a scene object.
window.expivi.setNodeProperty(aNodeName : string, aProperty : {name : string, value : any}) : Promise<number>;
Parameter Descriptions
Return a promise containing the number of nodes affected.
Parameter | Description | Type |
---|---|---|
aNodeName | The name of the scene object node to change its property. | string |
aProperty | An object { name: string, value: any } containing the name of the property and the value to be set. | { name: string, value: any } |
changeCameraZoom
Change the camera zoom by delta.
window.expivi.changeCameraZoom(aZoomDelta : number) : Promise<number>
Parameter Description
Parameter | Description | Type |
---|---|---|
aZoomDelta | The delta, in negative or positive direction, to change the zoom with. | number |
The zoom will be capped by the minimum & maximum zoom defined in Expivi’s editor.
Return a promise containing the applied delta.
saveConfiguration
Save/Serialize the configured product - see Serialization
.
window.expivi.saveConfiguration(aWidth : number, aHeight : number) : Promise<{
bundle_uuid : string,
configured_products: []
}>;
Parameter Descriptions
Parameter | Description | Type | Default Value |
---|---|---|---|
aWidth | (Optional) The width of the screenshot. | number | 512 |
aHeight | (Optional) The height of the screenshot. | number | 512 |
loadConfiguration
Load a previously configured product (serialized with saveConfiguration).
window.expivi.loadConfiguration(aConfiguration : {
bundle_uuid : string,
configured_products: []
}) : Promise<boolean>;
Reloading previous configurations can be done during initialization by providing the aConfiguredProduct attribute.
loadPreset
Load a preset configuration.
window.expivi.loadPreset(aProductSceneId : string | null, aPresetId : string) : Promise<boolean>;
You can apply preset only on an already created product of same catalogue id.
selectProductNode
Select active product node.
window.expivi.selectProductNode(aProductSceneId? : string) : Promise<ProductNode>;
Parameter Description
Parameter | Description | Type | Default Value |
---|---|---|---|
aProductSceneId | (Optional) The unique product ID to select (resolved from window.expivi.resolveProductNodes() ). | string | main product node |
When having more than one configurable product inside the viewer, active product node can be changed to set/get its attributes without providing product id. Selecting a product node is also useful when movement of objects inside the scene is also activated, selecting products will activate their movement options in that case.
autoRotateYAxis
Rotate the product automatically on the Y axis.
window.expivi.autoRotateYAxis(aProductSceneId? : string, aStopOnInteraction = true, aSpeed = 1, aMaxDegree = 360) : Promise<ProductNode>;
Parameter Descriptions
Parameter | Description | Type | Default Value |
---|---|---|---|
aProductSceneId | (Optional) The unique product ID to select (resolved from window.expivi.resolveProductNodes() ). | string | main product node |
aStopOnInteraction | (Optional) Stop the automatic rotation when the user interacts with the viewer. | boolean | true |
aSpeed | (Optional) The rotation speed of the animation. | number | 1.0 |
aMaxDegree | (Optional) The degree at which the animation will automatically stop. | number | 360.0 or infinite: -1 |
deselect
Deselect any selected node inside the viewer.
window.expivi.deselect() : Promise<boolean>;
deleteNode
Delete a scene node from the viewer.
window.expivi.deleteNode(aSceneNodeId : string) : Promise<SceneNode>;
Parameter Description
Return a promise containing the deleted scene node (if any).
Parameter | Description | Type |
---|---|---|
aSceneNodeId | Unique scene node ID (in case of product node, resolved from window.expivi.resolveProductNodes() ). | string |