Knowledge Center

Knowledge Center > Zuora CPQ > Zuora CPQ Development Resources > Zuora CPQ Component Library > Zuora CPQ Global Components > SelectProduct Component > Save Rate Plan Plugin Example

Save Rate Plan Plugin Example

This article describes the process of creating a sample custom Save Rate Plan Plugin on the SelectProduct component. The sample plugin does the following:

  • Detect and print the numbers of added, removed, updated, and unedited charge groups.
  • Validate if new charge groups were added on save.

Implement the Save Rate Plan Plugin

Follow these steps to set up the product catalog, create a plugin, and test the plugin.

To set up rate plans and the association between the rate plans:

  1. In your Zuora Product Catalog, add a product and a rate plan. Name the rate plan "SomeSampleRatePlan".
  2. Perform a Product Catalog Sync.

To create the plugin class and register the new plugin for the SelectProduct component:

  1. In Salesforce, create a new class, SampleImplementationForOnSavePlugin, using the code below.
  2. Navigate to Zuora Config > Component Registration.
  3. Click Edit for the SelectProduct component.
  4. In the Component Plugins section, for the Save Rate Plan Plugin type, specify SampleImplementationForOnSavePlugin in the Class Name field and click Update.

​​Example of the Component Plugin for Save Rate Plan Plugin

To test the newly added plugin:

  1. To test the new plug-in, add the Product and its rate plan, SomeSampleRatePlan, to a quote.
  2. When you click Save in the Product Selector, you will see the following error message:
    'You are not allowed to add new rate plans to this Quote.'

The following is a code for the sample plugin: 


global class SampleImplementationForOnSavePlugin implements zqu.SelectProductComponentOptions.ISaveRatePlanPlugin {
  public void onSave(List<zqu.zChargeGroup> addedChargeGroups, List<zqu.zChargeGroup> updatedChargeGroups, List<zqu.zChargeGroup> removedChargeGroups, 
  List<zqu.zChargeGroup> persistedChargeGroups){
    System.debug('zuora - SampleImplementationForOnSavePlugin - onSave executed');
    
    System.debug('zuora - SampleImplementationForOnSavePlugin - addedChargeGroups.size() : ' + addedChargeGroups.size());
    System.debug('zuora - SampleImplementationForOnSavePlugin - updatedChargeGroups.size() : ' + updatedChargeGroups.size());
    System.debug('zuora - SampleImplementationForOnSavePlugin - removedChargeGroups.size() : ' + removedChargeGroups.size());
    System.debug('zuora - SampleImplementationForOnSavePlugin - persistedChargeGroups.size() : ' + persistedChargeGroups.size());
    // Validate addedChargeGroups
    if(addedChargeGroups.size() > 0){
      throw new SavePluginException('You are not allowed to add new rate plans to this Quote.');
    }
  }
  
  global class SavePluginException extends Exception {}
}
Last modified

Tags

Classifications

(not set)