|
| 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. |
0 commit comments