# 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.
optionsOptional 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.
styleCodeThe 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.
componentComponent- Returns 
boolean 
# getPrice
Calculates the price of the given component code.
componentComponent 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.excludePlacementsA list of placement codes to be excluded from the price calculation.options.fixedPlacementsA list of placement codes that should reflect the current component selection price rather than respective min/max component prices.options.ignoreOptionalIgnores price of optional components when calculating min/max prices.options.ignorePlaceholdersIgnores price of placeholder components when calculating min/max prices.- Returns 
ObjectReturns 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.ignoreOptionalAllows optional placeholders to remain unfulfilled.options.excludePlacementsA 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.
controllerSource controller- Returns 
void 
# isSelected
Checks if a code is selected in the current state.
componentCodeComponent code to check- Returns 
boolean 
# acceptableComponents
Finds a list of components acceptable in the placement.
placementCodeTarget placement code- Returns 
ArrayReturns a list of placement + component objects supported in the placement. 
# findComponent
Finds a component object by the given component code.
codeComponent code- Returns 
Object 
# findPlacement
Finds a placement object by the given placement code.
codePlacement code- Returns 
Object 
# searchComponents
Find components in the placement that match given options.
placementCodePlacement code.searchOptions.codeComponent option code to search for.searchOptions.definitionOption definition code to search for.- Returns 
Array 
# updateComponent
If the selection is can be made, updates the selected component for the given placement.
placementCodeTarget placement codecomponentCodeComponent to be selected- Returns 
ObjectReturns 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.
placementCodeTarget placement codecomponentDefinitionNameComponent option definition name to searchcomponentOptionCodeNew option code to select- Returns 
ObjectReturns a previously selected component or {} if there was no component selected for the placement. 
# updateDynamicImage
Updates dynamic image reference associated with the placement.
placementCodeThe placement to be updated.options.titleThe image title.options.titleThe original image file name.options.urlThe source image URL in the original image format.options.pngUrlThe URL of the PNG version of the dynamic image.options.jpgUrlThe 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.
placementCodeThe placement code. Selected component must have custom attributes to begin with.changesThe 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.
placementCodeThe Placement to be updated.textThe new personalization text.updateOptions.noEnforceLimitDon'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.
resolvePromise* 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.
componentComponent to check availability
# getPrice
Allows the host site to override the default price calculation, and provide a custom price for the component.
componentComponent 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.
viewSelected view.stateThe selected state vector. The state does not have to match the currently active controller state.frameThe selected current frame.options.beforePlacementOnly 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.afterPlacementOnly generate rendering instructions for placements after given placement.options.baseWidthProvides the resulting image width, in case if not using background image elements.options.baseHeightProvides the base image height.- Returns 
stringImage URL