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
+15-9Lines changed: 15 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,13 @@ month_change: true
11
11
By extending [Discounts](discounts_guide.md), you can increase flexibility and control over how promotions are applied to suit your unique business rules.
12
12
Together with the existing [events](event_reference.md) and the [Discounts PHP API](discounts_api.md), extending discounts gives you the ability to cover additional use cases related to selling products.
13
13
14
+
!!! tip
15
+
16
+
If you prefer learning from videos, two presentations from Ibexa Summit 2025 cover the Discounts feature:
17
+
18
+
- Konrad Oboza: [Introduction to the Discounts system in Ibexa DXP](https://www.youtube.com/watch?v=kTgtxY38srw)
19
+
- Paweł Niedzielski: [Extending new Discounts to suit your needs](https://www.youtube.com/watch?v=pDJxEKJLwPs)
20
+
14
21
## Create custom conditions
15
22
16
23
With custom [conditions](discounts_api.md#conditions) you can create more advanced discounts that apply only in specific scenarios.
@@ -28,7 +35,7 @@ The following expressions are available for conditions and rules:
28
35
| --- | --- | --- | --- |
29
36
| Function |`get_current_region()`|[Region object](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-RegionInterface.html) of the current siteaccess.| Conditions, rules |
30
37
| Function |`is_in_category()`|`true/false`, depending if a product belongs to given [product categories](pim_guide.md#product-categories).| Conditions, rules |
31
-
| Function |`is_user_in_customer_group()`|`true/false`, depending if a user belongs to given [customer groups](customer_groups.md). | Conditions, rules |
38
+
| Function |`is_user_in_customer_group()`|`true/false`, depending if an user belongs to given [customer groups](customer_groups.md). | Conditions, rules |
32
39
| Function |`calculate_purchase_amount()`| Purchase amount, calculated for all products in the cart before the discounts are applied.| Conditions, rules |
33
40
| Function | <nobr>`is_product_in_product_codes()`</nobr> |`true/false`, depending if the product is part of the given list.| Conditions, rules |
34
41
| Variable |`cart`|[Cart object](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Cart-Value-CartInterface.html) associated with current context.| Conditions, rules |
@@ -40,7 +47,7 @@ The following expressions are available for conditions and rules:
40
47
### Custom expressions
41
48
42
49
You can create your own variables and functions to make creating the conditions easier.
43
-
To create the condition checking the registration date, the following example will use an additinal variable and a function:
50
+
To create the condition checking the registration date, the following example uses an additional variable and a function:
44
51
45
52
-`current_user`, a variable with the current [User object](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-User-User.html)
46
53
@@ -79,7 +86,7 @@ todo: verify
79
86
```
80
87
81
88
The expression can evaluate to `true` or `false` depending on the custom expressions values.
82
-
An additional variable, `today`, is defined to store the current date for comparison.
89
+
An additional variable, `date`, is defined to store the current date for comparison.
83
90
84
91
For each condition class you must create a dedicated condition factory, a class implementing the `\Ibexa\Discounts\Repository\DiscountCondition\DiscountConditionFactoryInterface` inteface.
85
92
@@ -95,11 +102,13 @@ Mark it as a service using the `ibexa.discounts.condition.factory` service tag a
95
102
todo
96
103
```
97
104
105
+
To learn how to integrate the custom conditions into the back office, see [Extend Discounts wizard](extend_discounts_wizard.md).
106
+
98
107
## Create custom rules
99
108
100
109
To implement a custom rule, create a class implementing the [`DiscountRuleInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountRuleInterface.html).
101
110
102
-
The following example implements a [purchasing power parity discount](https://en.wikipedia.org/wiki/Purchasing_power_parity), adjusting product's price in the cart based on buyer's region.
111
+
The following example implements a [purchasing power parity](https://en.wikipedia.org/wiki/Purchasing_power_parity) discount, adjusting product's price in the cart based on buyer's region.
103
112
104
113
``` php
105
114
todo
@@ -117,6 +126,8 @@ Mark it as a service using the `ibexa.discounts.condition.factory` service tag a
117
126
todo
118
127
```
119
128
129
+
To learn how to integrate the custom rules into the back office, see [Extend Discounts wizard](extend_discounts_wizard.md).
130
+
120
131
### Custom discount formatting
121
132
122
133
You can adjust how each discount type is displayed when using the [`ibexa_discounts_render_discount_badge` Twig function](discounts_twig_functions.md#ibexa_discounts_render_discount_badge) by implementing a custom formatter.
description: Integrate custom rules and conditions into the back office forms.
3
+
editions:
4
+
- lts-update
5
+
- commerce
6
+
month_change: true
7
+
---
8
+
9
+
## Extend Discounts wizard
10
+
11
+
To allow using your [custom conditions and rules](extend_discounts.md#create-custom-conditions) by the store managers, you need to integrate them into the back office discounts creation form.
12
+
13
+
The [`DiscountFormMapperInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-DiscountFormMapperInterface.html) is the service responsible for translating the form data into structures used by the PHP API.
14
+
15
+
The form uses a data driver approach, where the mapper provides all the data to the form and the form adjusts and created the fields as neccessary.
0 commit comments