Skip to content

Commit c375ffb

Browse files
committed
[Discounts] Added Twig reference
1 parent 478faec commit c375ffb

File tree

5 files changed

+117
-1
lines changed

5 files changed

+117
-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: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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 function 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 discount 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 current user has permissions to edit discounts.
75+
``` html+twig
76+
{% if ibexa_discounts_is_active(discount) %}
77+
<div>The discount is active</div>
78+
{% endif %}
79+
```
80+
81+
### `ibexa_discounts_form_themes()`
82+
83+
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.
84+
85+
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.
86+
87+
### `ibexa_discounts_can_edit()`
88+
89+
Helper function returning whether the current user has permissions to edit discounts.
90+
91+
### `ibexa_discounts_can_enable()`
92+
93+
Helper function returning whether the current user has permissions to enable discounts.
94+
95+
### `ibexa_discounts_can_disable()`
96+
97+
Helper function returning whether the current user has permissions to disable discounts.
98+
99+
### `ibexa_discounts_can_delete()`
100+
101+
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)