How to Use Secondary Key to Create Matrix Price Lists

In order to create a matrix price list, two logics are required – one generates the key, the other calculates the price list based on that key. The key generator logic must be specified as Matrix logic in the Price List setup.

Define the matrix key generator (matrix pricing logic):

  1. Go to Configuration > Calculation Logic > Generic Logic. Create a new logic and set Nature to Matrix.
  2. Define the logic's elements. Create one visible element which will return a list of keys generated based on input parameters. Below is an example of keys generated from Datacenters, Terms_Payments, Tiers, Customers, and Programs elements.


def datacenters = api.getElement("Datacenters")
 
def skus = []
 
// data centers
for (dc in datacenters) {
  def datacenter = dc.name
  def dcCode = dc.attribute2.replaceAll(" ", "_")
 
  def terms_payments = api.getElement("Terms_Payments")
  def tiers = api.getElement("Tiers")
  def customers = api.getElement("Customers")
  def programs = api.getElement("Programs")
 
  // terms
  for (tr in terms_payments) {
   
    // tiers
    for (ti in tiers) {
   
      // customers
      for (c in customers) {
 
        // programs
        for (pr in programs) {
          def sku = datacenter + "-" + tr + ti + "-" + c + "1" + pr    
          skus.add(sku)
        }
      }
    }
  } 
}
 
for (sku in skus) {
  api.trace("SKU", null, sku)
}
 
return skus

The code returns a list of SKU’s which are being used as secondary keys for Matrix Price List calculation. A sample trace of the above logic looks like this:

Define a price list logic which will reference the matrix logic and retrieve the key list:

  1. Go to Configuration > Calculation Logic > Generic Logic. Create a new logic.
  2. Create an element which retrieves the secondary key using the method api.getSecondaryKey().
  3. The returned key can be split into various components which will be used to calculate the price based on their variations.

    def key = api.getElement("Debug")=="No" ? api.getSecondaryKey() : "B1A-36PT5-C1S"
    
    def parts = key?.tokenize("-")
    
    return [
      dc: parts[0],
      term: parts[1][0..1],
      payment: parts[1][2],
      tier: parts[1][3..4],
      program: parts[2][0],
      version: parts[2][1],
      priceType: parts[2][2]
    ]
  4. This makes it possible to extract a secondary key component for subsequent substitutions. Like this:

    return api.getElement("SecondaryKey")?.dc  //for Datacenter

    or

    return api.getElement("SecondaryKey")?.term  //for Term
  5. Subsequent logic performs substitutions to build the SKU, look up currency, and calculate prices for the price list.

Found an issue in documentation? Write to us.