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)

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

DC1

  • 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.

  1. Go to Setup.

  2. In the Quick Find box, enter custom.

  3. Click Custom Metadata Types.

  4. Click Function Definition.

  5. Click Manage Function Definitions.

  6. Click New.

  7. 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. Function Definition Detail
  • Create a function definition in Product Console.
    • Define function definition as shown below. Product In Order
    • Define function definition arguments as shown below. Function Argument
    • Create function based context rule as shown below. Context Function General
    • Create advanced context rules condition for above rule as shown below. Context Function Rule
    • Create ruleset and its children rule assignment as shown below. Context Function Test Context Children Rule
  • Assign contextFunctionTest rule set to 500$ onetime charge of 200MBPS product as shown below MBPS

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

  • JOB

Context dimension mappings with functions must be converted to rule conditions with functions.