Knowledge Center

Knowledge Center > Commerce > Zuora for Salesforce Development Resources > Zuora for Salesforce Component Library > Zuora for Salesforce Global Components > QuickList Component > Allowed Records Plugin Example 2

Allowed Records Plugin Example 2

Overview

This article describes the process of creating a sample custom Allowed Records Plugin on the QuickList component. The example plugin is to be applied to the AddAddOnProducts Guided Selling Step to display only the product rate plans based on the previous step. The plugin uses a custom field on the Product Rate Plan object to filter the product rate plans.

Implement an Allowed Records Plugin​

Follow the steps given in this section to set up the product catalog, create a plugin, and test the plugin.

To set up the rate plans in Zuora Product Catalog and Zuora Quotes for the examle plugin:

  1. Create a custom field on the Product Rate Plan object in Zuora and in Zuora Quotes as below:
    • Custom field name: ProductTier
    • Field type: Picklist
    • Picklist values: Small, Medium, Large
  2. Create or edit the products and rate plan in the Zuora product catalog, and assign the field values for the new custom field.
  3. Synchronize the product catalog to Zuora Quotes.

To update the Guided Selling Step for the plugin:

  1. In Zuora Quotes, navigate to Zuora Config > Guided Product Selectors.
  2. Expand New Quote Flow, and edit AddAddOnProducts Guided Selling Step.
  3. Select Include Context Filters, and click Save.
    In order to have access to the rate plans selected in the previous step, the Guided Selling Step must have its Context Filter enabled.

To create the example plugin and register it:

  1. Create a new class, AllowedRatePlans, using the code below.
  2. Navigate to Zuora Config > Component Registration.
  3. Click Edit for the QuickList component with the name, AddAddOnProducts.
  4. In the Component Plugins section, for the Allowed Records Plugin type, specify AllowedRatePlans in the Class Name field.
    AllowedRecordsPlugin.png
  5. Click Update.

The following is the implementation of a sample AddRatePlands plugin. It uses the contextIds object that contains the rate plan ids selected in the previous step in the current Guided Selling Flow. The plugin retrieves those rate plan ids in a comma-separated list, using the key, selectedRatePlans.

global class AllowedRatePlans implements
   zqu.QuickListController.IAllowedRecordPlugin {   
    
   global Set<Id> getAllowedRecordIds(Map<Object, Object> contextIds, Map<String, String> pluginParams) {
      //Id rateplanId;       
      Set<Id> allowedIds = new Set<Id>();    

      List<zqu__ProductRatePlan__c> selectedRatePlans=new List<zqu__ProductRatePlan__c>();
      
      //Get the rate plan ids from the contextIds input key-value pair.      
      for (Object k: contextIds.keySet()) {         
         if (((String) k).equalsIgnoreCase('selectedRatePlans')) {
            Object ratePlanId = contextIds.get(k);
            
            List<String> ratePlanIds = ((String)ratePlanId).split(',', 0);
            selectedRatePlans = [SELECT Id, name, ProductTier__c FROM zqu__ProductRatePlan__c WHERE id in :ratePlanIds];
           
            break;
         }    
      }        
      List<zqu__ProductRatePlan__c> ratePlans = [SELECT Id, ProductTier__c FROM zqu__ProductRatePlan__c WHERE zqu__Deleted__c = false];
       
      //Filter down the list of product rate plans for the product rate plans based on ProductTier__c     
      for (zqu__ProductRatePlan__c ratePlan : ratePlans) {        
         for (zqu__ProductRatePlan__c selectedRatePlan1: selectedRatePlans) {
            if (ratePlan.ProductTier__c == selectedRatePlan1.ProductTier__c) {
               allowedIds.add(ratePlan.Id); 
               break;
            }
         }
      } 
      return allowedIds;   
   }
}

To test the new plugin:

  1. Create a quote for a new subscription.
  2. When you get to the Choose Product and Charges step, click New Quote Flow.
  3. Click the AddBaseProducts step and select one or more rate plans.
  4. Click Add and Next.
  5. In the AddAddOnProducts step, only the Add-On type rate plans with the same ProductTier__c values selected in the previous AddBaseProducts step will appear. For example, if you selected a product rate plan whose ProductTier__c is "Small", only the rate plans whose ProductTier__c is "Small" appear in the selection list.
Last modified
17:13, 12 Feb 2015

Tags

This page has no custom tags.

Classifications

(not set)