Implement an online order form for direct ordering: enter products by product number, add them to the basket and keep entries across the session.
With direct ordering, the buyer enters the product numbers of the desired products in an order form. They can then add all entered items to the basket with a single click. The prerequisite is that the customer has the corresponding product numbers, for example from a catalog.Nothing else is required for this. No additional scripts are needed.
The shop stores the products checked during a direct order that have not yet been added to the basket in the session. The cookie only contains the reference to the session. If saveCountInSession is enabled under checkout.directOrder, the shop also remembers the current number of input lines there.If the direct order form is called up again later, the stored product data is automatically filled into the corresponding input fields. This avoids having to re-enter the product number and quantity if the shop visitor has not yet added their selection to the basket but has visited other pages of the shop first.
This action checks the entry of a line and adds the product to the order form list. It does not add anything to the basket. There is a separate step for that, see Add items to the basket.
{{ foreach $cProduct in range(0, $wsDirectOrder.currentLines - 1) }} {{ var $cActionDirectOrderAdd = $wsActions.create("DirectOrderAdd", tag=string($cProduct)) }}{{ /foreach }}
The error messages can be placed either before or inside the form element. The DirectOrderAdd action does not report all errors on the same field:
Errors relating to the quantity are found under errorsByField.quantity.
Errors relating to the item number and the product are found under errorsByField.id.
Errors of the item number fields from itemNumberFields are found under the name of the respective input field. This applies to itemNumberCheckFailed and to missingId for an empty required field.
In this example, error messages are displayed if the quantity of an item is entered incorrectly.
In this example, error messages are displayed when adding an item. The second loop additionally outputs the errors of the item number fields. The type check is necessary because itemNumberFields also contains separators, and these have no name.
{{ foreach $cProduct in range(0, $wsDirectOrder.currentLines - 1) }} {{ var $cActionDirectOrderAdd = $wsActions.create("DirectOrderAdd", tag=string($cProduct)) }} ... {{ if $cActionDirectOrderAdd.errorsByField.id }} <div class="alert alert-danger"> Errors occurred: <ul> {{ foreach $err in $cActionDirectOrderAdd.errorsByField.id }} <li>{{ if $err.text }}{{= $err.text }}{{ else }}{{= $err.code }}{{ /if }}</li> {{ /foreach }} </ul> </div> {{ /if }} {{ foreach $field in $wsConfig.directOrder.itemNumberFields }} {{ if $field.type == "field" and $cActionDirectOrderAdd.errorsByField[$field.name] }} <div class="alert alert-danger"> {{ foreach $err in $cActionDirectOrderAdd.errorsByField[$field.name] }} {{ if $err.text }}{{= $err.text }}{{ else }}{{= $err.code }}{{ /if }} {{ /foreach }} </div> {{ /if }} {{ /foreach }}{{ /foreach }}
The output per item number field supplements the output of errorsByField.id; it does not replace it. If the combined item number cannot be assigned to a product, the action reports invalidId on the id field. This also applies if the line does not contain an id input field at all.
A separate form adds the entered items to the basket using the BasketItemAdd action. For each item, a hidden field named multiProducts.<product number>.quantity is submitted. If insert codes are active, the field multiProducts.<product number>.insert is submitted as well. Without this step, an order is never created.