Voucher input form with maximumCount check
The input form is only displayed as long as fewer vouchers have been redeemed than allowed. As soon as the upper limit is reached, the form disappears automatically.
Error messages (e.g. “Minimum order value not reached”) are defined and rendered via
components/errorAlert.htm.Displaying the list of redeemed vouchers
A separate small form with a unique ID is output for each voucher. Valid vouchers appear in green, invalid ones in red.Displaying all redeemed vouchers in the basket
In this example, all redeemed vouchers are shown in the basket. The customer can transparently see which codes are in the system and which one is currently being applied. Vouchers that have no effect are not added to the list and are indicated via an error message.Output voucher errors with reason and voucher ID
Instead of a generic notice, the customer sees the specific reason per voucher why the voucher does not apply. The texts come fromcheckout.voucherErrors; the fallback to code only kicks in if no text is maintained.
Always check
details.voucherId before rendering. The voucher ID is deliberately missing when the error comes from the summed minimum-order-value check. Which error is raised when is documented under When each error occurs.Free shipping method for voucher-only baskets
If a basket contains only (instant) vouchers, no physical shipping is required. For this case you can define a dedicated, always free shipping method undercheckout.shippingMethod: the basicCost scale sets the cost to 0 from a subtotal of 0, and the validation shippingMethodValidation.productType with rule: deny blocks the shipping method as soon as a regular product (product type standard) is in the basket — so it can only be selected for pure voucher baskets.
The value
standard in the ruleList is the value of the product type field of the products (the product data field defined as product type via content.usedFields) — not to be confused with the shipping method’s own type: "standard" parameter. Products for which the product type field is not set always pass the check.name, description and orderText refer to text snippets in this example, so the texts can be maintained per language via the text-snippet service.Offering purchased vouchers for download
This example is not about redemption but about selling: if a purchase voucher product was ordered, the shop generates a voucher code per ordered unit at order completion. The codes of a basket position are available in the template undervoucherIds; the associated PDF is generated via the URL parameter wsfilter=pdf from the view template stored on the product.
The following block outputs a download link per position and code. It is suitable for the order confirmation page and for the email template of the order confirmation.
The type
absolute generates a complete URL because emails cannot process relative links. The parameters voucherId and productId make the call independent of the session, so the link still works later on.voucher/default_voucher.htm stands here as a placeholder for the view template stored on the product in the “HTML template” field. How PDF views are built is described in PDF views.data.orderList.item[].voucher, see API reference orders.