$wsDirectOrder module, you read the state of a direct order. In a direct order, the customer places products into the basket directly by entering their item numbers, without searching for them individually in the shop. The module returns the current number of input lines and the items recorded so far, including their validity.
This page covers reading the direct-order state. Adding and deleting items happens via the DirectOrderAdd / DirectOrderDelete actions.
Basic concept
The order form is a form with several input lines. In each line, the customer enters an item number (and a quantity). When submitted, theDirectOrderAdd action checks whether the number exists and adds the product to the basket.
$wsDirectOrder provides the current state for this:
currentLines– how many input lines are currently displayed. The value comes from the configuration ($wsConfig.directOrder:initialNumbertomaximalNumber).items– the items already recorded, each withid,quantity, andvalid.
Validity
Thevalid field of an item indicates whether the entered item number exists in the shop and can be ordered. Evaluate it to give the customer immediate feedback on an invalid entry.
Module overview
Example / excerpt of$wsDirectOrder
| Variable | Type | Description |
|---|---|---|
currentLines | int | Current number of displayed input lines. |
items | array | Recorded order items (structure see below). |
items[])
| Property | Type | Description |
|---|---|---|
id | string | Entered item number. |
quantity | int | Entered quantity. |
valid | bool | true if the item number exists and can be ordered. |
Templates
By default, the order form is located in the templatemodule/directOrder.htm. Link it, e.g. in the footer (see example).
Variables
$wsDirectOrder.currentLines
Returns the current number of displayed input lines. The value is configured via$wsConfig.directOrder (initialNumber as the start, maximalNumber as the upper limit). Use it, for example, to generate exactly that many lines.
$wsDirectOrder.items
Returns the recorded order items. Use the line index to access a specific item (items[$index]).
Properties of an order item
| Property | Type | Description |
|---|---|---|
id | string | Entered item number. |
quantity | int | Entered quantity. |
valid | bool | true if the item number exists and can be ordered. |
Methods
No methods are available for$wsDirectOrder.
Actions
$wsDirectOrder itself does not provide any actions. Adding and deleting items happens via the actions.
Examples
Order form template
This example generates an input row for every configured line (currentLines). range(0, currentLines - 1) returns the indexes 0 to currentLines - 1. For each line, the actions DirectOrderAdd and DirectOrderDelete are created with the line index as tag, so that inputs and errors are assigned to the correct line. The ifNull('') filter sets an empty value if the line has not yet been filled in.
An order form with as many input rows as
currentLines specifies. Rows that have already been filled in are pre-populated with their item number and quantity.
Display error messages
TheDirectOrderAdd action reports errors per field via errorsByField. This example shows the errors for the item number (id) and the quantity (quantity) per line.
On invalid input (e.g. an invalid item number or quantity), the corresponding message appears in the affected line.
Link the page in the footer
You generate the link to the direct order withviewUrl(). Pass the path to the template as the argument.
A link that leads to the direct-order page.
Related links
- $wsActions – provides the actions
DirectOrderAdd/DirectOrderDeleteand the error structureerrorsByField. - $wsConfig.directOrder – configures the number of lines and additional item-number fields.
- Online order form – detailed practical example.
- checkout - Order process – configuration of the order process.
