Skip to main content

Rate Plan Customization Plugin Example

Zuora

Rate Plan Customization Plugin Example

This article presents a sample custom implementation of the Rate Plan Customization Plugin on the SelectProduct Component.

global class QPFTestPlugin implements zqu.SelectProductComponentOptions.IRatePlanCustomizationPlugin {
    public void updateZChargeGroups(zqu__Quote__c quote, 
        List<zqu.ZChargeGroup> zcgs) {
        if(zqu.zQuoteUtil.isFeatureEnabled) {
            System.debug('enter updateZChargeGroups');
            addTest(zcgs);
            //updateTest(zcgs);
            //removeTest(zcgs);
            System.debug('exit updateZChargeGroups');
        }
    }
    private void addTest(List<zqu.ZChargeGroup> zcgs) {
        zqu__ZFeature__c zFeature = 
            [Select Id, zqu__FeatureName__c, zqu__Description__c, zqu__Code__c, 
                zqu__ZuoraId__c 
                From zqu__ZFeature__c 
                Where Id = 'a0bj0000000dvE2'];
        zqu__QuoteProductFeature__c newQuoteFeature = 
            new zqu__QuoteProductFeature__c();
        newQuoteFeature.zqu__ZFeature__c = zFeature.Id;
        newQuoteFeature.zqu__FeatureZuoraId__c = zFeature.zqu__ZuoraId__c;
        newQuoteFeature.zqu__ZFeature__r = zFeature;
        newQuoteFeature.zqu__FeatureName__c = zFeature.zqu__FeatureName__c;
        newQuoteFeature.zqu__Description__c = zFeature.zqu__Description__c;
        newQuoteFeature.Custom_Field_Text_1__c = 'Feature 4.';
        for(zqu.ZChargeGroup zcg : zcgs) {
            zcg.quoteProductFeatures.add(newQuoteFeature);
            zcg.quoteProductFeaturesChanged = true;
            break;
        }
    }
    private void updateTest(List<zqu.ZChargeGroup> zcgs) {
        for(zqu.ZChargeGroup zcg : zcgs) {
            for(zqu__QuoteProductFeature__c quoteProductFeature : 
                zcg.quoteProductFeatures){
                if(zcg.allowFeatureChanges) {
                    quoteProductFeature.Custom_Field_Text_1__c = 
                    'Field Value After Modification.';
                    zcg.quoteProductFeaturesChanged = true;
    
                    System.debug('feature: ' + quoteProductFeature);
                }
            }
        }
    }
    private void removeTest(List<zqu.ZChargeGroup> zcgs) {
        for(zqu.ZChargeGroup zcg : zcgs) {
            if(zcg.quoteProductFeatures.size() > 0) {
                zcg.quoteProductFeatures.remove(zcg.quoteProductFeatures.size() - 1);
                zcg.quoteProductFeaturesChanged = true;
                break;      
            }      
        }
    }
}