You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/discounts/extend_discounts.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,6 +84,20 @@ Mark it as a service using the `ibexa.discounts.expression_language.function` se
84
84
85
85
Two new expressions are now available for use in custom conditions and rules.
86
86
87
+
When deciding whether to register a new custom variable or function, consider the following:
88
+
89
+
- variables are always evaluated by the expression engine and the result is available for all the rules and conditions specified in the discount
90
+
- functions are invoked only when the rule or condition using them is evaluated. If there are multiple conditions using them, they will be invoked multiple times
91
+
92
+
For performance reasons, it's recommended to:
93
+
94
+
- use variables only for lightweight calculations
95
+
- use functions for resource-intensive calculations (for example, checking customer's order history)
96
+
- implement caching (for example, in-memory) for function results to avoid redundant calculations within a single discount, if the function is used multiple times
97
+
- specify the most resource-intensive conditions as the last to evaluate. As all conditions must be met for the discount to apply, it's possible to skip evaluating them if the previous ones won't be met
98
+
99
+
In a production implementation, you should consider refactoring the `current_user_registration_date` variable into a `get_current_user_registration_date` function to avoid always loading the current user object and improve performance.
100
+
87
101
### Implement custom condition
88
102
89
103
The following example creates a new discount condition. It allows you to offer a special discount for customers on the date when their account was created, making use of the expressions added above.
0 commit comments