DeliveryscenarioAvailability
A DeliveryscenarioAvailability defines when a delivery scenario is available.
This can be done in two ways:
- By specifying a set of sales channels (required)
- By writing a script (optional)
In its simplest form, a DeliveryscenarioAvailability
looks like this:
1{
2 "saleschannels": [1, 2]
3}
This defines that the delivery scenario is available when used in the context of saleschannel 1
or 2
.
More complex logic can be specified by writing a small piece of JavaScript. To do so, you need to add a usescript
and script
field to the availability:
1{
2 "saleschannels": [1, 2],
3 "usescript": true,
4 "script": "// script here"
5}
Note that the list of sales channel IDs is still required: the script can only restrict this set further.
A simple example of a delivery scenario script:
1return order.tickets.length < 3 && saleschannel.typeid == 3002;
This script states that the current delivery scenario is only available if the amount of tickets in the order is less than 3 and the current sales channel is a web sales channel.
With this script the DeliveryscenarioAvailability
would look like this:
1{
2 "saleschannels": [1, 2],
3 "usescript": true,
4 "script": "return order.tickets.length < 3 && saleschannel.typeid == 3002;"
5}
The following variables are available in the script:
order
saleschannel
You can use any valid JavaScript syntax (including conditionals and loops). Note that each script has a strict time limit.
Fields
Field | Description |
---|---|
saleschannels int[] (required) | An array of sales channel IDs for which this delivery scenario can be used Example value:[ 1, 3, 4 ] |
script string (required) | Script used to determine availability of the delivery scenario Example value:"return order.tickets.length < 3 && saleschannel.typeid == 3002;" |
usescript bool (required) | Use a script to refine the set of sales channels? |
Example
1{
2 "saleschannels": [ 1, 3, 4 ],
3 "script": "return order.tickets.length < 3 && saleschannel.typeid == 3002;",
4 "usescript": false
5}