View source | View content page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Show collection (0 pages)
Collections help


Projects:LoyaltyManagement/Technical Guide/AccumulateHook

How to create a Hook to accumulate points


This document explains an example how to create a hook for the accumulation of loyalty point. In this case it is useful to get used to work with hooks on WebPOS. You can find some information on the following link.

You can find the list of hooks implemented on WebPOS on the following link, in this case we recommend to use OPBOS_PreOrderSave hook.

Create the hook

You will need to know the basics of Openbravo's JavaScript code, such as modularization, Component Providers, etc...

Here you can find an example of a dummy implementation of OBPOS_PreOrderSave hook on an accumulating process.

// Listen for OBPOS_PreOrderSave hook
  OB.MobileApp.model.hookManager.registerHook('OBPOS_PreOrderSave', function (args, callbacks) {
    // Condition for accumulation
    if (args.receipt.get('isAccumulating')) {
      // If you want to pick your previously defined accumulations rules
      OB.Dal.find(OB.Model.OBLOY_LoyaltyProgram, {
        active: true
      }, function (programs) {
        var program =;
        var criteria = {
                _whereClause: " WHERE loyaltyProgram = '" + + "' AND active = 'true'"
        OB.Dal.find(OB.Model.OBLOY_AccumulationRules, criteria, function (rules) {
          // rules will be a collection of your Accumulation Rules defined for your Loyalty Program
          // Calculate points & when the process ends call OB.MobileApp.model.hookManager.callbackExecutor(args, callbacks);
          //IMPORTANT: Take into account any asynchrony
          args.receipt.set('accumulatedPoints', 999);
          OB.MobileApp.model.hookManager.callbackExecutor(args, callbacks);
      // If args.receipt.get('accumulatedPoints') is populated it will appear on the printed ticket if Loyalty Receipt Template is selected on Organization window.
    } else {
      OB.MobileApp.model.hookManager.callbackExecutor(args, callbacks);

Retrieved from ""

This page has been accessed 396 times. This page was last modified on 27 October 2014, at 07:12. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.