Download PDF
Download page Pricing Callback Class.
Pricing Callback Class
The Pricing Callback class enables you to add pricing logic to your cart that cannot be achieved by out-of-the-box pricing mechanisms, such as Price Rulesets and Price Matrices. The Pricing Callback is executed for each bundled product or standalone in the cart. A separate transaction call is initiated for each product in the cart. The Pricing Callback is invoked when you are on the cart page. The pricing callback is invoked during pricing action and executes the various methods in the BASEPRICE and ADJUSTMENT modes.
To use the Pricing Callback you must create a custom Apex class that implements the Apttus_Config2.CustomClass.IPricingCallback3 interface and register the custom apex class with Pricing Callback Class. You must write your custom logic in the custom apex class.
The following methods are available in the Apttus_Config2.CustomClass.IPricingCallback3 interface:
Method | Signature | Description |
---|---|---|
afterPricing() | void afterPricing(Apttus_Config2.ProductConfiguration.LineItemColl) | You can use this method to define the logic to be executed after Net Price calculation. The collection of line items currently in the cart is passed as an input parameter to this method. |
afterPricingLineItem() | void afterPricingLineItem(Apttus_Config2.ProductConfiguration.LineItemColl, Apttus_Config2.LineItem) | You can use this method to define custom logic that has to be applied after the Net Price has been calculated. This method called for each line item in the cart​. |
beforePricing() | void beforePricing(Apttus_Config2.ProductConfiguration.LineItemColl) | You can use this method to define the logic for net price calculation. In this method, no pricelist item is associated to the cart line items. Price Matrix and Price Ruleset calculation occurs when the mode of the callback is BASEPRICE Mode. |
beforePricingLineItem() | void beforePricingLineItem(Apttus_Config2.ProductConfiguration.LineItemColl, Apttus_Config2.LineItem) | You can use this method to define custom logic that has to be applied after the Base Price has been calculated but before the downstream prices like Base Extended Price, and Extended Price is calculated. This method called for each line item in the cart​. |
finish() | void finish() | This is the last method that is executed after the callback is invoked. |
setMode() | void setMode(Apttus_Config2.CustomClass.PricingMode) | You can use this method to specify the mode of the callback. Based on the mode of the callback you can define different business logic. The modes are:
|
start() | void start(Apttus_Config2.ProductConfiguration) | This is the first method that is executed when the callback is invoked. |
onPriceItemSet() | void onPriceItemSet(Apttus_Config2__PriceListItem__c, Apttus_Config2.LineItem) | You can use this method to associate custom fields with line items and apply logic related to price list item. This method is called on each line item. |
BASEPRICE mode is used primarily to set quantity, term and so on in the line item beforePricing() method. Base price mode is called for each line number. If there are two line numbers, the BASEPRICE mode would be invoked twice. The following methods in the callback are invoked during the BASEPRICE mode:
- start()
- setMode()
- beforePricing()
- onPriceItemSet()
- afterPricing()
- finish()
The line item collection in beforePricing() may not match the line item collection in afterPricing() if the product has multiple charge types. In this case, the afterPricing() method would have more line items. Any modification to custom fields needs to be done in the beforePricing() method.
ADJUSTMENT mode is invoked for all items (including options) in the cart after applying adjustments to compute Net Price. Only the adjusted price or the adjustment amount may be changed at this point. The following methods in the callback are invoked during the Adjustment mode:
- start()
- setMode()
- beforePricing()
- beforePricingLineItem()
- afterPricingLineItem()
- afterPricing()
- finish()
Depending on the discount applied at the group level, the beforePricingLineItem() and afterPricingLineItem() may be applied at the option lines after the execution of the methods at the bundle lines level.
When you define a pricing callback, ensure that you verify the following:
- Implement the latest interface version 3 for your pricing callback class.
- Choose the correct mode for your custom logic because all or some of the methods in the class will be called during each mode.
- The most widely used modes are either BASEPRICE or ADJUSTMENT.
- It is recommended to have logic in the BASEPRICE mode only, in the beforePricing(), beforePricingLineItem(), afterPricing(), and afterPricingLineItem() methods. ADJUSTMENT mode is an exception and should be reviewed with the Product team (PM, PST, Engg) before approval for implementation.
- ADJUSTMENT mode does not have all option items in Large Cart mode and hence it is preferable not to use this mode.
- ADJUSTMENT mode is not executed when the parameter isCartTotalingDisabled is set to true in the Configure Products button URL.
- Any DML statement is not required. All changes related to line items are covered regardless of DML. However, if there are other object record changes then make sure that the query is not called multiple times in a single transaction of pricing. For example, if you want to compute the Base Price which is based on some custom logic, assign the final calculated value to Quantity, Selling Term, or any custom field on the line item.
- If your logic is dependent on Base Price calculation, then make sure to use Base Price Override field of Line Item. You can put the newly computed Base Price in this field and then in the next mode, the system will take the value of Base Price from the override field to compute Extended Price and Net Price.
- When you do a Reprice on the Cart page and change any field on the line item, which is used in Price Matrix or Price Ruleset, then BASEPRICE mode will get called along with ADJUSTMENT mode. If you change fields on the line item which are not impacting Base Price Calculations (e.g. Giving 10% discount on a bundle line item), then only ADJUSTMENT mode is called.
- Option Line Item are not be called in beforePricingLineItem() or afterPricingLineItem() methods in any mode. If you need to work on an option line item, then do it in beforePricing() or afterPricing() methods.
- If you want to write any custom logic that depends on price list item fields, then you should use onPriceItemSet() method. In this method, the system determines the corresponding price list item for a line item.
- If you have queries in the callback class, it is advisable to do it in start() method so that it is not repeated for each line item in the before/after methods.
- Use of updatePrice() method should be avoided unless there is approval from the Product team.
- The custom fields on Price List Item are not retrieved in the onPriceItemSet method automatically. To auto-retrieve the custom fields in this method, the Administrator must create a new entry named APTS_PriceListItemCustomFields in Admin. Enter the API names of the custom field of the Price List Item in the Code field separated by a comma or on a new line.
/**
* Apttus Config & Pricing
* DefaultPricingCallback2
*
* @2011-2014 Apttus Inc. All rights reserved.
*/
global with sharing class SamplePricingCallback2 implements Apttus_Config2.CustomClass.IPricingCallback3 {
private Apttus_Config2.ProductConfiguration contextCart;
private Apttus_Config2.CustomClass.PricingMode currentMode;
/**
* Callback at the beginning of the pricing call.
* Use the start method to initialize state
* @param cart the cart object
*/
global void start(Apttus_Config2.ProductConfiguration cart) {
this.contextCart = cart;
}
/**
* Callback to indicate the pricing mode
* @param mode the pricing mode
*/
global void setMode(Apttus_Config2.CustomClass.PricingMode mode) {
this.currentMode = mode;
}
/**
* Callback after the price list item is set on the given line item
* @param itemSO the price list item associated with the line item
* @param lineItemMO the line item
*/
global void onPriceItemSet(Apttus_Config2__PriceListItem__c itemSO, Apttus_Config2.LineItem lineItemMO){
}
/**
* Callback before pricing the line item collection
* Use this method to do all required pre-processing to prepare the line items for pricing.
* @param itemColl the line item collection to pre-process
*/
global void beforePricing(Apttus_Config2.ProductConfiguration.LineItemColl itemColl) {
}
/**
* Callback before pricing the given line item in the line item collection
* Use this method to do all required pre-processing to prepare the line item for pricing.
* @param itemColl the line item collectionholding the line item
* @param lineItemMO the line item to pre-process
*/
global void beforePricingLineItem(Apttus_Config2.ProductConfiguration.LineItemColl itemColl, Apttus_Config2.LineItem lineItemMO) {
}
/**
* Callback after pricing the given line item in the line item collection
* Use this method to do all required post-processing after the line item is priced
* @param itemColl the line item collection holding the line item
* @param lineItemMO the line item to post-process
*/
global void afterPricingLineItem(Apttus_Config2.ProductConfiguration.LineItemColl itemColl, Apttus_Config2.LineItem lineItemMO) {
}
/**
* Callback after pricing the line item collection
* Use this method to do all required post-processing after line items are priced.
* @param itemColl the line item collection to post-process
*/
global void afterPricing(Apttus_Config2.ProductConfiguration.LineItemColl itemColl) {
}
/**
* Callback after all batches of line items are processed
* Use the finish method to release state
*/
global void finish() {
}
}