Skip to content

Commit 1eab7ae

Browse files
committed
Started working on Forms
1 parent d10add4 commit 1eab7ae

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

docs/discounts/extend_discounts.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ month_change: true
1111
By extending [Discounts](discounts_guide.md), you can increase flexibility and control over how promotions are applied to suit your unique business rules.
1212
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.
1313

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+
1421
## Create custom conditions
1522

1623
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:
2835
| --- | --- | --- | --- |
2936
| 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 |
3037
| 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 |
3239
| Function | `calculate_purchase_amount()` | Purchase amount, calculated for all products in the cart before the discounts are applied.| Conditions, rules |
3340
| Function | <nobr>`is_product_in_product_codes()`</nobr> | `true/false`, depending if the product is part of the given list.| Conditions, rules |
3441
| 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:
4047
### Custom expressions
4148

4249
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:
4451

4552
- `current_user`, a variable with the current [User object](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-User-User.html)
4653

@@ -79,7 +86,7 @@ todo: verify
7986
```
8087

8188
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.
8390

8491
For each condition class you must create a dedicated condition factory, a class implementing the `\Ibexa\Discounts\Repository\DiscountCondition\DiscountConditionFactoryInterface` inteface.
8592

@@ -95,11 +102,13 @@ Mark it as a service using the `ibexa.discounts.condition.factory` service tag a
95102
todo
96103
```
97104

105+
To learn how to integrate the custom conditions into the back office, see [Extend Discounts wizard](extend_discounts_wizard.md).
106+
98107
## Create custom rules
99108

100109
To implement a custom rule, create a class implementing the [`DiscountRuleInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Value-DiscountRuleInterface.html).
101110

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.
103112

104113
``` php
105114
todo
@@ -117,6 +126,8 @@ Mark it as a service using the `ibexa.discounts.condition.factory` service tag a
117126
todo
118127
```
119128

129+
To learn how to integrate the custom rules into the back office, see [Extend Discounts wizard](extend_discounts_wizard.md).
130+
120131
### Custom discount formatting
121132

122133
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.
@@ -145,8 +156,3 @@ todo
145156
todo
146157
```
147158

148-
## Form integration
149-
150-
### Condition
151-
152-
### Rules
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
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.
16+
17+
### Condition
18+
19+
### Rules

0 commit comments

Comments
 (0)