Using this event, we can cancel an event, or an option based on the event names and conditions.
Cancelable Events is a class that allows an operation to be canceled before it is completed.
In the Suite Commerce Extensibility API, most operations have a before and after event. The operation can be canceled before it is executed by creating a component listener that subscribes to the before event. Business logic in the listener can then throw an error or return a Deferred object in the rejected state.
For example, in CartComponent.js, the AddLine method is used to add a line to the cart. The beforeAddLine event occurs before the line is added and the afterAddLine events occurs after the line is added.
Examples
Canceling an option selection from a listener by throwing an error:
pdp_component.on('beforeOptionSelection', function() {
if(someCondition)
throw new Error('Canceling select option.');
});
Copy
Canceling an option selection from a listener by returning a rejected promise:
pdp_component.on('beforeOptionSelection', function() {
if(someCondition)
return jQuery.Deferred().reject(new Error('Canceling select option.'));
});