Writing availability scripts
Availability scripts allow you to really refine when a certain object is available in a certain context. For example:
Availability scripts can be defined for:
When defining availability, you will always first select a subset of the sales channels. The availability script will further refine this selection.
Simple script
The script should be written in Javascript and should always return a boolean. It’s not necessary to write a function, only the script itself.
For example, this simple script will return true when the current date is between 01/01/2015 and 01/04/2015:
1var now = new Date();
2var start = new Date(2015,0,1);
3var end = new Date(2015,0,4);
4return start.getTime() < now.getTime() && now.getTime() < end.getTime();
Script with context
In the script there are a few context variables available:
For example this script will return true when tickets for a certain event are in the order:
1if (!order) return false;
2
3for (var i = 0 ; i < order.tickets.length ; i++) {
4 var t = order.tickets[i];
5 if (t.eventid == 777711) {
6 return true;
7 }
8} return false;
The order will contain a lookup
section that allows you to lookup related objects to the order. For example: you can retrieve the pricetypeid for alle tickettypepriceids in the order. The idea is similar to the order lookup that is available when creating order documents or order mails, but the content of the lookup here is much more limited for performance reasons.
Important: keep in mind that the order
context will sometimes be empty, so make sure your script handles the case of an empty order correctly.