Validation is designed to create additional checks for changes to orders and customers made by system users. Checks are applied not only when editing in the order/customer card, but in mass operations.
A boolean expression is specified in the condition; if true, the action will be canceled and the user will receive an error message.
In the condition, you can work with the object being acted upon (this is order
or customer
), as well as with the object changeSet
(type Change\EntityChangeSet
), which contains information about the fields to be changed.
changeSet.isUpdate() and changeSet.hasChangedField('payments.status')
In some cases, validation requires checking some attributes of the user who changes the data in the order/customer. For example, to check that the user is in a specific group. You can view the user changing the data by using the user()
function.
-
- Prohibition to change the payment status of the order
changeSet.isUpdate() and changeSet.hasChangedField('payments.status')
-
- Delivery date must be today or later
order.deliveryDate < date('now 00:00:00') and (
(changeSet.isCreate() and order.deliveryDate) or
(changeSet.isUpdate() and changeSet.hasChangedField('delivery_date'))
)
-
- Only the user of the "Logistician" group can carry out the shipment.
Note
By default, there is no "Logistician" group in the system, but you can create the user groups you need.
changeSet.hasChangedField('shipped') and not user().hasGroup('logist')
-
- User can change only certain fields
changeSet.hasChangesExcluding(['status', 'first_name', 'last_name'])