Subscribe to Events

This topic applies to

Applies to

Aconcagua | SuiteCommerce Web Stores

Use the <component>.on(event, event_handler) method for a component to create a listener and subscribe to an event.

Each listener takes two arguments:

  • event – declares the name of the event to listen to.

  • event_handler – declares the function to process the results of the operation that triggered the event. In general, each event handler receives a single argument.

The following code example shows how to subscribe to the afterOptionSelection event for the PDP and then log the result to the browser console:

var pdp = container.getComponent('PDP');

// ...

pdp.on('afterOptionSelection', function(event) {
  console.log('option ' + event.optionCartId + ' was selected with value ' + event.value)
});