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

PDF Books
Show collection (0 pages)
Collections help

Search

Projects:LoyaltyManagement/Technical Guide/AccumulateHook

How to create a Hook to accumulate points

Introduction

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. http://wiki.openbravo.com/wiki/How_to_Add_Hooks#How_to_provide_logic_in_external_modules

You can find the list of hooks implemented on WebPOS on the following link, in this case we recommend to use OPBOS_PreOrderSave hook. http://wiki.openbravo.com/wiki/List_of_Hooks_in_Web_POS

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 = programs.at(0);
        var criteria = {
                _whereClause: " WHERE loyaltyProgram = '" + program.id + "' 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 "http://wiki.openbravo.com/wiki/Projects:LoyaltyManagement/Technical_Guide/AccumulateHook"

This page has been accessed 366 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.