Let's create a simple example from scratch. Let’s assume we don’t want to allow a negative product price, as you can see in the following screenshot.
To avoid negative prices in the system, we need to create a new Attribute Constraint to ensure a product's price is always positive. We'll create a "Min Constraint" to enforce this:
- Navigate: In the Backoffice, go to System→Validation→Constraints.
- Then, we click on the chevron next to the "+" button to create a new constraint.
- We select "Attribute constraint", scroll down, and click on "Min Constraint".
In the configuration wizard, we set the constraint ID to "PositivePriceRow", and set the "Minimal value" to 0.
Then, we specify the "Composed type" as PriceRow and the "Attribute descriptor" as Price.
It should look like this:
We click "Next", and on the 2nd screen of the wizard, enter the error message "Price must be non-negative".
After entering all these details, we click on "Finish" to save the new constraint.
After searching for our new constraint of via refreshing the list of validation constraints, it shows up.
As you can see, it is enabled but needs the validation engine to be reloaded to become actively enforced by the system.
Thus, we reload the validation engine to apply the changes to the active system.
Let’s switch back to the product.
Now, any attempt to save a product with a negative price will trigger the validation error message and force the user to enter a positive value, as shown in the following screenshot.
Note
As you can see, already negative-defined prices remain in the system, and assigned products also do not change. But as soon as you try to edit that price, you are only allowed to save it with a positive value.
Let‘s have a look at another example of creating a validation constraint in the following video.
Good to Know
- Attribute validation constraints are applied to items like Products, PriceRows or even Users. They are enforced by the validation engine and remain independent of any synchronization status.
- Validation is only enforced on the Server side, and not applicable to client side entries (For example, end user website entries during shopping and checkout).