# Controller Class
# Controller Properties
# blueprint
- Returns The currently loaded blueprint definition.
# state
- Returns The array of current component selections.
# Controller Methods
# load
Loads product information and begins customization process.
options
Optional parameter overrides, for example a new product list.- Returns
void
# destroy
Destroys the controller instance and frees the resources.
- Returns
void
# products
Gets a list of currently loaded products.
- Returns
[string]
# findProduct
Searches currently loaded blueprint for a product in the list of related products.
styleCode
The product id to find.- Returns
Object
# isAvailable
Checks if component is available, i.e. it is not disabled in the Customize backend, and has sufficient inventory levels.
component
Component- Returns
boolean
# getPrice
Calculates the price of the given component code.
component
Component to calculate the price for- Returns
number
# statePrice
Calculates the overall state price, including the range of possible prices if different component selections were made.
options.excludePlacements
A list of placement codes to be excluded from the price calculation.options.fixedPlacements
A list of placement codes that should reflect the current component selection price rather than respective min/max component prices.options.ignoreOptional
Ignores price of optional components when calculating min/max prices.options.ignorePlaceholders
Ignores price of placeholder components when calculating min/max prices.- Returns
Object
Returns an object with the current, minimal, and maximum prices based on currently selected state.
# canBuild
Checks whether current state can be built, for example if placeholders have been replaced with actual options.
options.ignoreOptional
Allows optional placeholders to remain unfulfilled.options.excludePlacements
A list of placements to ignore when considering whether the design can be built.- Returns
boolean
# transferCompatibleState
Transfer a compatible state selections from another to this controller, optionally bringing over only the specified placements. A state selection is considered to be compatible is it matches a placement code and a component can be selected in that placement.
controller
Source controller- Returns
void
# isSelected
Checks if a code is selected in the current state.
componentCode
Component code to check- Returns
boolean
# acceptableComponents
Finds a list of components acceptable in the placement.
placementCode
Target placement code- Returns
Array
Returns a list of placement + component objects supported in the placement.
# findComponent
Finds a component object by the given component code.
code
Component code- Returns
Object
# findPlacement
Finds a placement object by the given placement code.
code
Placement code- Returns
Object
# searchComponents
Find components in the placement that match given options.
placementCode
Placement code.searchOptions.code
Component option code to search for.searchOptions.definition
Option definition code to search for.- Returns
Array
# updateComponent
If the selection is can be made, updates the selected component for the given placement.
placementCode
Target placement codecomponentCode
Component to be selected- Returns
Object
Returns a previously selected component or {} if there was no component selected for the placement.
# updateSimilarComponent
A method that is similar to updateComponent, however it allow to search from a new component based on the current selection and a new option code. For example, a text personalization is typically comprised from a font and a color. Using this method allows to easily update one or another without affecting the text entry or the other selected option. If the selection is can be made, updates the selected component for the given placement.
placementCode
Target placement codecomponentDefinitionName
Component option definition name to searchcomponentOptionCode
New option code to select- Returns
Object
Returns a previously selected component or {} if there was no component selected for the placement.
# updateDynamicImage
Updates dynamic image reference associated with the placement.
placementCode
The placement to be updated.options.title
The image title.options.title
The original image file name.options.url
The source image URL in the original image format.options.pngUrl
The URL of the PNG version of the dynamic image.options.jpgUrl
The URL of the PNG version of the dynamic image.- Returns
Promise(Object)
# commitCustomAttributes
Commits custom attribute changes to a component currently selected in the placement. Modifies .custom attributes map for the component, performs necessary validations, and updates image views as necessary.
placementCode
The placement code. Selected component must have custom attributes to begin with.changes
The dictionary of custom attributes values changes to be applied to the component- Returns
Promise(boolean)
Returns a promise that resolves into an object specifying whether any changes were actually committed.
# updatePersonalization
Updates the personalization text for a placement.
placementCode
The Placement to be updated.text
The new personalization text.updateOptions.noEnforceLimit
Don't enforce personalization-limit when accepting new text.- Returns
Promise(Object)
Returns a promise that resolves to an object:{ accepted: true }
if personalization is accepted as-is{ accepted: true, as: 'filtered text'}
if personalization is accepted in filtered form.{ accepted: false, lastValid: 'last valid text' }
if personalization text is rejected due to configured restrictions.
# Controller Events
Controllers may emit a number of events that can be used to detect important changes within a controller or provide some additional data to controllers.
# beforeLoadBlueprint
Triggered just before the controller loads a new blueprint.
# afterInitializeState
Triggered after the controller had created the initial state vector. .state property can now be used to examine the state.
# afterInitializeBlueprint
Triggered after the controller has performed all actions necessary to initialize the product state using a freshly loaded blueprint. .blueprint property can now be used to examine the product blueprint.
# stateChanged
Triggered whenever the product selected components, personalization, or customization attributes had changed, due to a user selection or a programmatic change.
# initializeAvailability
Called after the product blueprint has been loaded, but not completely initialized yet to give the host site a chance to retrieve the inventory levels for blueprint components. These inventory levels may later be used to figure out the component availability and update the state vector.
resolve
Promise
* After the availability state has been retrieved, the host site must invoke the resolve callback passed as a parameter.
# isAvailable
Allows the host site to determine whether the given component is available for customization and selection, e.g. if the component is in stock.
component
Component to check availability
# getPrice
Allows the host site to override the default price calculation, and provide a custom price for the component.
component
Component to calculate a price for
# repaint
Triggered whenever the controller state had changed enough that the related product image needs to be refreshed.
# 2D Image Rendering Methods
A set of methods that assist creation of 2D stacked-image product renderings.
# makeFrameUrl
Creates an image URL that renders the product selections made for the given state.
view
Selected view.state
The selected state vector. The state does not have to match the currently active controller state.frame
The selected current frame.options.beforePlacement
Only generate rendering instructions for placements before given placement. Used to create "split" renders to allow for dynamic image customizations, if the dynamic image is overlayed by an another component.options.afterPlacement
Only generate rendering instructions for placements after given placement.options.baseWidth
Provides the resulting image width, in case if not using background image elements.options.baseHeight
Provides the base image height.- Returns
string
Image URL