Some things do not come back
Opened cosmetics, food already started, a piece of furniture built to measure. Those products should not be in the form at all - or visible but greyed out.
The situation
The range holds 4,000 products, of which 60 are hygiene articles and a few dozen are made to measure. You do not want to maintain that by hand, and the customer should not learn only after submitting that it will not work.
First level: it applies by itself
Vouchers and discount lines cannot be selected at all. Only ordinary products of an order appear in the form. There is nothing to configure.
Vouchers and discounts cannot be selected in the first place.
Second level: a custom field on the product
Single products can be taken out of returns on the product itself, through a custom field, without a line of code. That is the route for the sixty hygiene articles.
On the product itself, without a line of code.
Third level: a condition in Twig
For everything that cannot be pinned to a single product there is a Twig condition. It runs for each order line; lineItem gets you the line, lineItem.product the product and lineItem.order the order. Setting isValid to false excludes it.
The Twig you enter runs for every product of the order. To exclude a product from a return shipment you have to set the variable "isValid" to false.
The customer sees that they exist
Excluded lines do not disappear, they sit greyed out in the list. That saves the question of why something is missing.
Which settings this uses
| Setting | Technical name | What it does |
|---|---|---|
| Enable custom conditions for products | productRestrictionStatus | Switches the Twig check on. |
| Twig Syntax | productRestrictionTwig | The expression that runs for each order line. |