Skip to content

Commit c7b190b

Browse files
[Discounts] Added Twig reference (#2782)
* [PHP API] Discounts (#2763) * [PHP API REF] Added Discount packages * Generated PHP API for Discounts * Discount product guide * Fixed links and navigation * Removed nav * Fixed links * Fixed typo * Fixed badges * Removed whitespace * Fixes before review * After review fixes * Currency remark * Discount migrations (#2768) * [Discounts] Added migration doc * Added files * Update docs/content_management/data_migration/importing_data.md * Applied suggestions from code review (#2767) Co-authored-by: julitafalcondusza <[email protected]> * [Discounts] Search overview (#2773) * [Discounts] Search overview * Fixes before review * Reworded Type sort clause * Update docs/search/discounts_search_reference/discounts_sort_clauses.md Co-authored-by: julitafalcondusza <[email protected]> --------- Co-authored-by: julitafalcondusza <[email protected]> * [Discounts] Event reference (#2776) * [Discounts] Added event reference * Fixed links * Fixes before review * Removed column * [Discounts] Mentioned discounts in pricing and customer groups (#2775) * Mentioned discounts in pricing and customer groups * Before review fixes * Added mention to the PIM guide * [Discounts] Discount policies (#2771) * Permissions * Build fixes * Fixed links * Fixed last links * Removed link * Apply suggestions from code review Co-authored-by: julitafalcondusza <[email protected]> --------- Co-authored-by: julitafalcondusza <[email protected]> * Discounts update (#2774) * Added update instructions * Fixed link * [Discounts] Added Twig reference * Self review * Apply suggestions from code review Co-authored-by: julitafalcondusza <[email protected]> --------- Co-authored-by: julitafalcondusza <[email protected]>
1 parent a4aafd4 commit c7b190b

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

docs/templating/twig_function_reference/ai_actions_twig_functions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
description: AI Actions functions allows you to embed AI Actions in your templates
33
page_type: reference
44
month_change: false
5+
edition: lts-update
56
---
67

78
# AI Actions Twig functions
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
description: Discounts Twig Functions allow you to operate on discounts in your templates.
3+
page_type: reference
4+
month_change: true
5+
editions:
6+
- lts-update
7+
- commerce
8+
---
9+
10+
# Discounts Twig functions
11+
12+
Discounts Twig Functions allow you to operate on discounts in your templates.
13+
14+
## Filters
15+
16+
### `ibexa_render_discount_rule_type`
17+
18+
This filter transforms the discount type (`fixed_amount` or `percentage`) into a human-friendly and translated label.
19+
20+
``` html+twig
21+
{% set rule_type = discount.getRule().getType() %}
22+
23+
<span class="ibexa-icon-tag">
24+
<svg class="ibexa-icon ibexa-icon--small">
25+
<use xlink:href="{{ ibexa_icon_path('discount-coupon') }}"></use>
26+
</svg>
27+
{{ rule_type|ibexa_render_discount_rule_type }}
28+
</span>
29+
```
30+
31+
## Functions
32+
33+
### `ibexa_discounts_render_discount_badge()`
34+
35+
Use the `ibexa_discounts_render_discount_badge` to render a badge indicating the discounted amount, for example on product cards.
36+
37+
``` html+twig
38+
{% if ibexa_storefront_are_discounts_enabled() %}
39+
{% block product_discount_price_info %}
40+
<div class="ibexa-store-product__discount-price-info">
41+
{% include '@ibexadesign/storefront/component/discount/discount_price.html.twig' with {
42+
original_price: original_price,
43+
} %}
44+
{% embed '@ibexadesign/storefront/component/discount/discount_badge.html.twig' with {
45+
size: 'small',
46+
} %}
47+
{% block content %}
48+
{{- ibexa_discounts_render_discount_badge(discount, price_money) -}}
49+
{% endblock %}
50+
{% endembed %}
51+
</div>
52+
{% endblock %}
53+
{% endif %}
54+
```
55+
56+
### `ibexa_get_original_price()`
57+
58+
Displays the product price before the discount was applied.
59+
60+
``` html+twig
61+
{{ ibexa_get_original_price(product)|ibexa_format_price ?: '-' }}
62+
```
63+
64+
### `ibexa_format_discount_value()`
65+
66+
Formats the discount value for each discount type, for example, by displaying `-10 EUR` or `-10%`.
67+
68+
``` html+twig
69+
content: ibexa_format_discount_value(discount),
70+
```
71+
72+
### `ibexa_discounts_is_active()`
73+
74+
Helper function returning whether the discount is currently active.
75+
76+
``` html+twig
77+
{% if ibexa_discounts_is_active(discount) %}
78+
<div>The discount is active</div>
79+
{% endif %}
80+
```
81+
82+
### `ibexa_discounts_form_themes()`
83+
84+
The `ibexa_discounts_form_themes` function serves as an extension point to provide new [form themes]([[= symfony_doc =]]/form/form_themes.html) for the discount form.
85+
86+
To add new ones, create a class implementing the [FormThemeProviderInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Discounts-Admin-Form-FormThemeProviderInterface.html) interface and provide them in the `getFormThemes` method.
87+
88+
### `ibexa_discounts_can_edit()`
89+
90+
Helper function returning whether the current user has permissions to edit discounts.
91+
92+
### `ibexa_discounts_can_enable()`
93+
94+
Helper function returning whether the current user has permissions to enable discounts.
95+
96+
### `ibexa_discounts_can_disable()`
97+
98+
Helper function returning whether the current user has permissions to disable discounts.
99+
100+
### `ibexa_discounts_can_delete()`
101+
102+
Helper function returning whether the current user has permissions to delete discounts.

docs/templating/twig_function_reference/storefront_twig_functions.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,16 @@ You can use this, for example, to [parametrize the display of products by using
109109

110110
``` html+twig
111111
{{ ibexa_get_anonymous_user_id() }}
112-
```
112+
```
113+
114+
### `ibexa_storefront_are_discounts_enabled()`
115+
116+
This function detects if the [Discounts LTS Update](discounts_guide.md) is installed.
117+
118+
``` html+twig
119+
{% if ibexa_storefront_are_discounts_enabled() %}
120+
<div class="ibexa-store-maincart-item__subtotal-original-price-net ibexa-store-discount-price">
121+
{{- product_price_original_subtotal -}}
122+
</div>
123+
{% endif %}
124+
```

docs/templating/twig_function_reference/twig_function_reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ In addition to the [native functions provided by Twig](https://twig.symfony.com/
2222
"templating/twig_function_reference/url_twig_functions",
2323
"templating/twig_function_reference/date_twig_filters",
2424
"templating/twig_function_reference/ai_actions_twig_functions",
25+
"templating/twig_function_reference/discounts_twig_functions",
2526
], columns=4) =]]

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ nav:
313313
- URL Twig functions: templating/twig_function_reference/url_twig_functions.md
314314
- User Twig functions: templating/twig_function_reference/user_twig_functions.md
315315
- AI Twig functions: templating/twig_function_reference/ai_actions_twig_functions.md
316+
- Discounts functions: templating/twig_function_reference/discounts_twig_functions.md
316317
- Twig Components: templating/components.md
317318
- URLs and routes:
318319
- URLs and routes: templating/urls_and_routes/urls_and_routes.md

0 commit comments

Comments
 (0)