Awarding Points for Claims based on its Store Price

Blank 26/11/2024 08:54 - 26/11/2024 08:54

This will just be a quick little guide on writing a Custom Points Rule Type that will let you award points based on the Price that is offered in the Store

 

A few pre-requisites

  1. You should have an eCommerce Store setup, You can see our documentation for that here: https://docs.kademi.co/programs/ecom/
  2. You should have setup a Pricing Rule in your eCommerce Store You can see our documentation for that here: https://docs.kademi.co/programs/ecom/ecom-030/ecom-030-010/poverview-1.html
  3. Be familiar with the development process of Custom Points Rule Types, You can see our documentation for that here: https://docs.kademi.co/programs/dev/d9/incent010/pintroduction.html

 

The code we will be using for the PAS will be as follows

Basically the workflow is as follows

  1. First we define our data series manager object to a shorthand variable
  2. We then use the method "productPrice" which takes in the Sales Data Record and a String which is the code for the store name
  3. Behind the scenes thic will do the lookup for any pricing rules that the product and user meet the eligibility requirements for (Such as Promotion, Group, Product Category etc)
  4. It will calculate the price using the pricing rules that are deemed eligible and then return that to us
  5. Then we can use an extra field on the Sales Data Record that is called "quantity" to multiply our price award by and then award that to the user with the return
function calcStorePrice(record, ruleParams, pas, recip) {

var dsm = services.dataSeriesManager;
var prodPrice = dsm.productPrice(record, ruleParams.storeName);
var finalPrice = prodPrice * record.fieldValue("quantity");
return finalPrice;

}

You can reach you can reach your eCommerce Store using the following infographic

And on the configuration page for your Points Allocation Source you can select your Points Rule Type and configure the Store Name field

 

In this blog article the example pricing rule we are using will add 5 and then multiply by 15

And you can see here we have a Sales Data Record where the user sold a Strimmer and the Quantity of what was sold is 50

 

 

If we take a look at the price of the Strimmer SKU we can see it is 200

 

If we take the ID of the Record (84359693) and chuck it into the PAS Tester you can see that our code ran and its given us an award value based on the Price in the Store multiplied by the Quantity sold

 

 

For a rundown on the process thats actually happening here is the following

  1. We look up the Price of the Product SKU in the store which is 200
  2. We find an eligible pricing rule, Since we only have 1 we use that, It will first add 5 (205) and then multiply by 15 (3075)
  3. We then take the final price (3075) and multiply it by the quantity on the record which is 50 and that gives us our final award (153750)