You are here:
Overriding Default Functions
To override default JavaScript functions, the descendant class can override certain behavior in the ancestor class by specifying the modified behavior in protected methods (similar to the object-oriented technique of Java protected methods).
For details about adding pre- and post-processing logic, see Adding Pre- and Post-Processing Logic.
This mechanism enables customers to override a function of the default JavaScript controller. The function must meet the following criteria:
-
The function must be a scope function, that is, $scope.function.
-
The function must be defined in the allowlist. Using an allowlist avoids abusive overrides of key functionality.
You can override the following controllers:
Controller |
Functions |
|---|---|
CPQPromotionItemController |
$scope.beforeAddToCartHook(payload) |
$scope.afterAddToCartHook(payload) |
|
CPQPromotionsController |
$scope.beforeDeletePromotionItemHook(payload) |
scope.afterDeletePromotionItemHook(payload); |
|
CPQCartItemController |
$scope.beforeAddToCartHook(payload) |
$scope.afterAddToCartHook(payload); |
|
$scope.beforeDeleteItemFromCartHook(payload) |
|
$scope.afterDeleteItemFromCartHook(payload) |
Using this approach to override functions decreases maintenance and the risk of missing functionality in future releases. It also decreases maintenance needs.
Sample Controller Override
vlocity.cardframework.registerModule.controller('customOverrideController',
['$scope', 'CPQOverrideService', function($scope, CPQOverrideService) {
#var overrideFunctions = {
'beforeAddToCartHook': function(parent, obj) {
alert('Hurray!');;
}
};
CPQOverrideService.addToOverrideList('CPQCartItemController', overrideFunctions);
}]);
To override a controller:
- Create a new controller.
- Go to the Vlocity Template that contains the function to override.
-
On the HTML Code tab, enter the appropriate markup to initialize the
custom controller. For example:
<div ng-controller="customOverrideController"></div> - On the JavaScript Code tab, enter the appropriate code to register the custom controller and override the default function using CPQOverrideService.

