Skip to content

[Discounts] Added Twig reference #2782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
description: AI Actions functions allows you to embed AI Actions in your templates
page_type: reference
month_change: false
edition: lts-update
---

# AI Actions Twig functions
Expand Down
102 changes: 102 additions & 0 deletions docs/templating/twig_function_reference/discounts_twig_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---

Check warning on line 1 in docs/templating/twig_function_reference/discounts_twig_functions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/templating/twig_function_reference/discounts_twig_functions.md#L1

[Ibexa.ReadingLevel] The grade level is 10.80. Aim for 8th grade or lower by using shorter sentences and words.
Raw output
{"message": "[Ibexa.ReadingLevel] The grade level is 10.80. Aim for 8th grade or lower by using shorter sentences and words.", "location": {"path": "docs/templating/twig_function_reference/discounts_twig_functions.md", "range": {"start": {"line": 1, "column": 1}}}, "severity": "WARNING"}
description: Discounts Twig Functions allow you to operate on discounts in your templates.
page_type: reference
month_change: true
editions:
- lts-update
- commerce
---

# Discounts Twig functions

Discounts Twig Functions allow you to operate on discounts in your templates.

## Filters

### `ibexa_render_discount_rule_type`

This filter transforms the discount type (`fixed_amount` or `percentage`) into a human-friendly and translated label.

``` html+twig
{% set rule_type = discount.getRule().getType() %}

<span class="ibexa-icon-tag">
<svg class="ibexa-icon ibexa-icon--small">
<use xlink:href="{{ ibexa_icon_path('discount-coupon') }}"></use>
</svg>
{{ rule_type|ibexa_render_discount_rule_type }}
</span>
```

## Functions

### `ibexa_discounts_render_discount_badge()`

Use the `ibexa_discounts_render_discount_badge` to render a badge indicating the discounted amount, for example on product cards.

``` html+twig
{% if ibexa_storefront_are_discounts_enabled() %}
{% block product_discount_price_info %}
<div class="ibexa-store-product__discount-price-info">
{% include '@ibexadesign/storefront/component/discount/discount_price.html.twig' with {
original_price: original_price,
} %}
{% embed '@ibexadesign/storefront/component/discount/discount_badge.html.twig' with {
size: 'small',
} %}
{% block content %}
{{- ibexa_discounts_render_discount_badge(discount, price_money) -}}
{% endblock %}
{% endembed %}
</div>
{% endblock %}
{% endif %}
```

### `ibexa_get_original_price()`

Displays the product price before the discount was applied.

``` html+twig
{{ ibexa_get_original_price(product)|ibexa_format_price ?: '-' }}
```

### `ibexa_format_discount_value()`

Formats the discount value for each discount type, for example, by displaying `-10 EUR` or `-10%`.

``` html+twig
content: ibexa_format_discount_value(discount),
```

### `ibexa_discounts_is_active()`

Helper function returning whether the discount is currently active.

``` html+twig
{% if ibexa_discounts_is_active(discount) %}
<div>The discount is active</div>
{% endif %}
```

### `ibexa_discounts_form_themes()`

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.

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.

Check failure on line 86 in docs/templating/twig_function_reference/discounts_twig_functions.md

View workflow job for this annotation

GitHub Actions / vale

[vale] docs/templating/twig_function_reference/discounts_twig_functions.md#L86

[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'
Raw output
{"message": "[Ibexa.VariablesGlobal] Use global variable '[[= product_name_base =]]' instead of 'Ibexa'", "location": {"path": "docs/templating/twig_function_reference/discounts_twig_functions.md", "range": {"start": {"line": 86, "column": 118}}}, "severity": "ERROR"}

### `ibexa_discounts_can_edit()`

Helper function returning whether the current user has permissions to edit discounts.

### `ibexa_discounts_can_enable()`

Helper function returning whether the current user has permissions to enable discounts.

### `ibexa_discounts_can_disable()`

Helper function returning whether the current user has permissions to disable discounts.

### `ibexa_discounts_can_delete()`

Helper function returning whether the current user has permissions to delete discounts.
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ You can use this, for example, to [parametrize the display of products by using

``` html+twig
{{ ibexa_get_anonymous_user_id() }}
```
```

### `ibexa_storefront_are_discounts_enabled()`

This function detects if the [Discounts LTS Update](discounts_guide.md) is installed.

``` html+twig
{% if ibexa_storefront_are_discounts_enabled() %}
<div class="ibexa-store-maincart-item__subtotal-original-price-net ibexa-store-discount-price">
{{- product_price_original_subtotal -}}
</div>
{% endif %}
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ In addition to the [native functions provided by Twig](https://twig.symfony.com/
"templating/twig_function_reference/url_twig_functions",
"templating/twig_function_reference/date_twig_filters",
"templating/twig_function_reference/ai_actions_twig_functions",
"templating/twig_function_reference/discounts_twig_functions",
], columns=4) =]]
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ nav:
- URL Twig functions: templating/twig_function_reference/url_twig_functions.md
- User Twig functions: templating/twig_function_reference/user_twig_functions.md
- AI Twig functions: templating/twig_function_reference/ai_actions_twig_functions.md
- Discounts functions: templating/twig_function_reference/discounts_twig_functions.md
- Twig Components: templating/components.md
- URLs and routes:
- URLs and routes: templating/urls_and_routes/urls_and_routes.md
Expand Down