$wsDirectOrder module, you can read the state of a direct order. Here, the customer records products by entering their item numbers in an order form, without having to search for them individually in the shop. They then transfer all recorded items to the basket in one step. The module returns the current number of input lines as well as the items recorded so far.
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 the corresponding quantity. When submitted, theDirectOrderAdd action checks whether the input can be assigned to a product and writes the line to the session’s order form list. Nothing reaches the basket at this point.
Transferring to the basket is a separate, second step: using the separate form and the BasketItemAdd action, all recorded items are submitted at once. The example Transfer items to the basket shows what this looks like.
$wsDirectOrder provides the current state:
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,valid, andinsert.
Invalid input
An invalid input does not create a line initems. If an item number cannot be assigned to a product or the quantity is invalid, the DirectOrderAdd action reports the error via errorsByField. The example Display error messages shows how to output these messages.
Module overview
Example / excerpt of$wsDirectOrder
Properties of an order item (
items[])
Templates
By default, the order form can be found in the templatemodules/directOrder.htm. Link it, for example, 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. You can use the line index to access a specific item (items[$index]).
Properties of an order item
Because
id contains the determined product number, an input field pre-filled with items[…].id no longer shows the customer’s original input after submission. However, you need exactly this product number when transferring to the basket.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 field-related errors via errorsByField. Not all errors are attached to the same field:
- Errors relating to the item number and the product can be found under
errorsByField.id. - Errors relating to the quantity are under
errorsByField.quantity. - Errors of the item number fields from
itemNumberFieldsare under the name of the respective input field, for exampleerrorsByField.firstField. This concerns the error messagesitemNumberCheckFailedandmissingIdfor an empty required field.
id) and the quantity (quantity) per line.
itemNumberFields also contains separators, and these have no name.
On invalid input, for example an invalid item number or quantity, the corresponding message appears in the affected line.
Transfer items to the basket
The items recorded withDirectOrderAdd are initially only in the order form list. A separate form transfers them to the basket with the BasketItemAdd action. For each recorded item, a hidden field named multiProducts.<productNumber>.quantity is sent. If insert codes are enabled, the field multiProducts.<productNumber>.insert is also added for each item.
There is a button that adds all recorded items with their quantity and, if applicable, their insert code to the basket. As long as no items have been recorded, the button is disabled.
The field name is the determined product number from
items[…].id, not the customer’s input. A variant is therefore passed via multiProducts.<productNumber>.<variant>.quantity. If one of the submitted items is invalid, the shop adds none of them to the basket.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.
- Basket:
BasketItemAddaction for transferring the items to the basket.
