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):
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:
api.getSecondaryKey()
.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] ] |
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 |