-
Notifications
You must be signed in to change notification settings - Fork 63
Chapter 5 Actions
Sometimes what you need to do with a product is both variable and based on some kind of conditions that are too complicated to be a general feature of Salor Retail. For this purpose, Actions are provided.
Actions take place when certain events are encountered, the most important being add_to_order
. Actions can be scoped to apply to a single item, an item in a category, or an item in a certain location.
For ease of use, Actions have some common pre-programmed logic to them, like multiplying the price, or subtracting from it.
For more complicated situations, you can use V8 JavaScript code that will be executed on the back end. A restricted API is provided to you for coding.
Here is an example of an action that gives a 10% rebate(discount) on a product when it is in a certain location.
As you can see, the code is very simple, and we suggest you always keep your actions simple. If you actually need something more complex, it may be a good idea to contact us to develop the feature for you, it may even be worthwhile to add it to the core code.
From the source code:
# Welcome to one of the most complicated bits of code in the system.
# The basic idea:
# The action.value is a float from 0-1.0 That represents the amount of the
# price to discount once the threshold action.value2 is met.
# IF This action applies to a Category or a Location, then we need to get all the
# order items present in that Category or Location, and Discount the LEAST expensive
# item.
Discounting After Threshold is a round about way to say: By x get x+1 free, or discounted. So if you sell Notebooks for $1 and if someone buys 4 they get the 5th free, then you would create an Action with a value of 1.0 (Full purchase price discount) and Value 2 set to 5.
I suppose it would have been better named "Discount exactly at threshold" but c'est la vie. This means that for every 4 Notebooks + 1 (5) The +1 will be free:
This is for a Discount after threshold with a value of 1.0 and a value2 of 5 (i.e. buy 4 get 1)
- 1 x Notebook = $1
- 2 x Notebook = $2
- 3 x Notebook = $3
- 4 x Notebook = $4
- 5 x Notebook = $4
- 6 x Notebook = $5
- 7 x Notebook = $6
- 8 x Notebook = $7
- 9 x Notebook = $8
- 10 x Notbook = $80
A simple trick to remember is that: Whatever the number you have to buy to get the discount, add 1. So if they have to buy 10 and get the 11th free, then value2 should be 11, not 10.