Use Functions and Context Rules with the Standard Cart APIs
- Create a pricelist with the following products and prices.
- Prod1 (Product2):
- Onetime charge - $10(Price)
- 200MBPS (Product2):
- Onetime charge - $10(Price)
- Onetime charge - $500(Price)
- Prod1 (Product2):
As you can see here, 200MBPS
has $10 and $500 as one time price. Consider a use case where we can create context rules which validates if Prod1
is part of the cart or not.
- If it is part of the cart, then the price for
200MBPS
is $500 - Else, price for
200MBPS
is 10$
- Ensure that catalog has following products.
- Prod1
- 200MBPS
- Create following one time prices for each of the products.
- Prod1
- Onetime charge - $10
- 200MBPS
- Onetime charge - $10
- Onetime charge - $500
- Prod1
- The following class defines context rules function
ProductInOrder
, which validates if a given product code is part of the cart or not - Ensure sure to update this class to support managed package by appending
vlocity_cmt
for the following global classes:- VlocityOpenInterface
- CpqCartDocument
- CpqCartDocumentItem
- FlowStaticMap
To add the function definitions in custom metadata, perform the following.
-
Go to Setup.
-
In the Quick Find box, enter custom.
-
Click Custom Metadata Types.
-
Click Function Definition.
-
Click Manage Function Definitions.
-
Click New.
-
Specify settings as follows:
- Label: The function name displayed in the list on the Function Definitions tab.
- Function Definition Name: The unique function name used by the API and managed packages, and which you use in formulas. The name must begin with a letter and use only alphanumeric characters and underscores. The name cannot end with an underscore or have two consecutive underscores.
- ClassName: The Apex class containing the method that implements the logic for the function.
- Method Name: The method that implements the logic for the function.
- Create a function definition in Product Console.
- Define function definition as shown below.
- Define function definition arguments as shown below.
- Create function based context rule as shown below.
- Create advanced context rules condition for above rule as shown below.
- Create ruleset and its children rule assignment as shown below.
- Assign contextFunctionTest rule set to 500$ onetime charge of 200MBPS product as shown below
Generate EPC Compile data. This job initializes the cache data.
On the EPC Jobs page, click Start next to GENERATE COMPILE DATA. From the Price List dropdown list, select the price lists, and then click Apply
Context dimension mappings with functions must be converted to rule conditions with functions.