Business rules allow you to define exactly how certain operations should be performed at various places in the retail system. Rules are extremely flexible for advanced users even permitting your own code to be called in some circumstances.Some examples:
- You wish to print a seasonal message on receipts, between 2 dates, only on sales over $x and not to trade customers or those purchasing certain products.
- There is a very specific pricing requirement that does not cleanly fit into normal pricing options.
- You are wanting to enable multiple overlapping special promotion vouchers and redemption.
Rules consist of several parts, the definition of the rule that broadly defines what the rule is, how it can be preselected for execution and which machine will be called to implement the machine.
The rule definition defines the rule in terms of description, time periods and broad conditions. This definition is controlled by application and cannot be altered.
Each rule definition includes a single machine to implement the rule. These machines are called by the application whenever it thinks the rule may apply. The machine is free to apply whatever logic it wishes and return optional commands to affect the state of the sale.
You can define your own machine and deliver it as compiled code, or use a range of pre built machinesWhen building your own machine, keep the following points in mind
- If your machine is in code form, you may be inside the POS space, or an external process.
- You will be called speculatively. Each call and response does not mean the POS will apply your commands at that time. To get performance in some cases the engine will call all rules in parallel to see which ones are valid, before calling them a second time. Some rules are also called by internal regression testing functionality, so you might be called for a "test" rather than "live".
- You should avoid external actions or side effects, such as writing databases, as you may not be executing on the machine that is invoking the rule. Specifically, rules are capable of being invoked over the network and your implementation logic does not receive knowledge of this.
- You are passed large amounts of data about the sale and environment and should restrict your logic to the arguments supplied.
- Recheck all conditions, do not rely on the system calling you alone. Rule definitions may be incorrectly created causing your machine to be executed when it shouldn't.