diff --git a/docs/templating/twig_function_reference/ai_actions_twig_functions.md b/docs/templating/twig_function_reference/ai_actions_twig_functions.md index 2b01673bc6..66779e2496 100644 --- a/docs/templating/twig_function_reference/ai_actions_twig_functions.md +++ b/docs/templating/twig_function_reference/ai_actions_twig_functions.md @@ -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 diff --git a/docs/templating/twig_function_reference/discounts_twig_functions.md b/docs/templating/twig_function_reference/discounts_twig_functions.md new file mode 100644 index 0000000000..8e8863716a --- /dev/null +++ b/docs/templating/twig_function_reference/discounts_twig_functions.md @@ -0,0 +1,102 @@ +--- +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() %} + + + + + + {{ rule_type|ibexa_render_discount_rule_type }} + +``` + +## 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 %} +
+ {% 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 %} +
+ {% 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) %} +
The discount is active
+{% 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. + +### `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. diff --git a/docs/templating/twig_function_reference/storefront_twig_functions.md b/docs/templating/twig_function_reference/storefront_twig_functions.md index dce6c682da..5450ff9820 100644 --- a/docs/templating/twig_function_reference/storefront_twig_functions.md +++ b/docs/templating/twig_function_reference/storefront_twig_functions.md @@ -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() }} -``` \ No newline at end of file +``` + +### `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() %} +
+ {{- product_price_original_subtotal -}} +
+{% endif %} +``` diff --git a/docs/templating/twig_function_reference/twig_function_reference.md b/docs/templating/twig_function_reference/twig_function_reference.md index 301f9f9cc1..abba7c79b3 100644 --- a/docs/templating/twig_function_reference/twig_function_reference.md +++ b/docs/templating/twig_function_reference/twig_function_reference.md @@ -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) =]] diff --git a/mkdocs.yml b/mkdocs.yml index 20be1066a9..947a7ef67c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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