Custom Flow for Pricing Variable Calculation
You can implement custom flow for pricing variable calculation with Standard Cart APIs. The process involves 2 steps:
- Setting Up the Interface
- Using the Existing Data
-
Create a custom apex class as follows: Ensure to add the namespace of the org before class and method names in the managed orgs.
-
Create an interface as follows:
-
Run EPC Compile job.
The data passed in the input and output map of the calculate
method is as follows:
- String
objectType
: This field stores the type of object passed like orderItem. It can be fetched usingget
operator. - Boolean
isRoot
: This value represents if the item being calculated is the bundle's root. It can be fetched usingget
operator. - Double
effectiveQuantity
: This field stores the quantity of the item passed. It can be fetched usingget
operator. - Map<String, Object>
pricingVariableCodeValueMap
: This map stores values of relevant pricing variables mapped to its code. It can be fetched usingget
operator.
- Map<String, Integer>
pricingVariableCodeToRoundingScale
: This has the map for rounding scale to pricing variable code. It can be fetched usingget
operator. - Map<String, String>
pricingVariableCodeToFieldBindingLabels
: This has the map for field binding labels to pricing variable code. It can be fetched usingget
operator. - String
isCostAndMarginFeatureEnabled
: This value represents if Cost and Margin feature is enabled. It can be fetched usingget
operator. - String
marginCalculationType
: This field stores margin calculation type which is information relevant to cost and margin feature. It can be fetched usingget
operator. - CartDocument
cartDocument
: This is a custom-type map that stores extensive information about the current cart. This cannot be extracted directly usingget
operator. Please use methods specifically designed for CartDocument to get relevant information. For more information, see Use Cart Documents. - String
itemId
: This stores the itemId for the current lineitem that is being processed. Depending on the org GUID (UseAssetReferenceIdForParentAndRoot
CPQ Config) value, it can be salesforceId or assetreferenceId. It can be fetched usingget
operator.
NOTE:
Please do not try using debug statements that serialize the input map.
System.debug('debug post input: '+json.serialize(input));
Input map contains an object for CartDocument, which is a custom Java type and cannot be serialized directly by the apex layer. Please use methods specifically designed for CartDocument to get relevant information.
- Map<String, Object>
calculatedPricingLogData
: This stores the pricing information for pricing variables of the processed item. It can be fetched usingget
operator.
- Based on the itemId (salesforceId or GUID) in the input map, additional queries can be written to find out more details about the item including relational fields.
- Query to get the GUID status of the org:
- To get the XLI custom field values without doing an additional SOQL call, we can use the ‘fields’ param in the getCartItems API. This would populate this custom field response in cartDocument in case it is a non-null value.