Exceptions

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.

deinshop.de/dvsn/return-shipment/create/…
Linen shirtSW-10024Size: M1Product defective
Voucher 20 €-

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.

Product · Custom fields
Exclude from return shipments

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.

Settings · Products - conditions
Enable custom conditions for products{% if lineItem.product and lineItem.product.productNumber == 'abc-12345' %}{% set isValid = false %}{% endif %}

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.

deinshop.de/dvsn/return-shipment/create/…
Linen shirtSW-10024Size: M1Product defective
Toothbrush setSW-10088--
Table lampSW-101022Product incorrectly delivered

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.
Where it ends The Twig condition is powerful, but it is code in a text field. A typo shows up only when a customer opens the form - it is worth testing.