{% macro display_product_price(product, with_tax) %}
    {% import '@CoreShopFrontend/Common/Macro/currency.html.twig' as currency %}

    {% if with_tax is null %}
        {% set with_tax = coreshop_display_with_tax(coreshop.context) %}
    {% endif %}

    {% set priceUnformatted = product|coreshop_product_price(coreshop.context, with_tax) %}
    {% set price = currency.convertAndFormat(priceUnformatted) %}
    {% set discountUnformatted = product|coreshop_product_discount(coreshop.context, with_tax) %}
    {% set discount = currency.convertAndFormat(discountUnformatted) %}
    {% set discountPriceUnformatted = product|coreshop_product_discount_price(coreshop.context, with_tax) %}
    {% set discountPrice = currency.convertAndFormat(discountPriceUnformatted) %}
    {% set retailPriceUnformatted = product|coreshop_product_retail_price(coreshop.context, with_tax) %}
    {% set retailPrice = currency.convertAndFormat(retailPriceUnformatted) %}

    <span class="price-new" {{ coreshop_test_html_attribute('product-price', price) }}>{{ price }}</span>
    {% if priceUnformatted < discountPriceUnformatted %}
        <span class="price-old" {{ coreshop_test_html_attribute('product-original-price', discountPrice) }}>{{ discountPrice }}</span>
    {% elseif priceUnformatted < retailPriceUnformatted %}
        <span class="price-old" {{ coreshop_test_html_attribute('product-original-price', discountPrice) }}>{{ retailPrice }}</span>
    {% endif %}
    {% if discountUnformatted > 0 %}
        <span class="price-discount" {{ coreshop_test_html_attribute('product-discount', discount) }}>(-{{ discount }})</span>
    {% endif %}
{% endmacro %}

{% macro display_product_unit_prices(product, with_tax) %}
    {% import '@CoreShopFrontend/Common/Macro/currency.html.twig' as currency %}
    {% import _self as product_price %}

    {% if with_tax is null %}
        {% set with_tax = true %}
    {% endif %}

    {% set defaultUnitDefinition = product.unitDefinitions.defaultUnitDefinition %}
    {% set additionalUnitDefinitions = product.unitDefinitions.additionalUnitDefinitions %}

    <div class="price default-unit-price">

        {% set price_suffix_label = product.itemQuantityFactor > 1
            ? 'coreshop.ui.price.per_unit_name_and_quantity_factor'|trans|format(product.itemQuantityFactor, defaultUnitDefinition.unit.translation(app.request.locale).fullLabel)
            : 'coreshop.ui.price.per_unit_name'|trans|format(defaultUnitDefinition.unit.translation(app.request.locale).fullLabel)
        %}

        <span class="price-head">{{ 'coreshop.ui.price'|trans }} {{ price_suffix_label }}:</span> {{ product_price.display_product_price(product) }}
        <div class="tax">
            {{ 'coreshop.ui.product.tax.inc'|trans|format(product|coreshop_product_tax_rate(coreshop.context)) }} ({{ currency.convertAndFormat(product|coreshop_product_tax_amount(coreshop.context)) }})
        </div>
    </div>

    {% if additionalUnitDefinitions|length > 0 %}
        <div class="additional-units-prices">
            <div class="card">
                <div class="card-header">
                    {{ 'coreshop.ui.additional_units'|trans }}
                </div>
                <ul class="list-group list-group-flush">
                    {% for additionalUnit in additionalUnitDefinitions %}
                        <li class="list-group-item">
                            {% set additionalUnitPrice = product|coreshop_product_price(coreshop.context|merge({unitDefinition: additionalUnit}), with_tax) %}
                            {% set additionalUnitPrice = currency.convertAndFormat(additionalUnitPrice) %}
                            <span class="price-head">{{ 'coreshop.ui.price'|trans }} per {{ additionalUnit.unit.translation(app.request.locale).fullLabel }}:</span>
                            <span class="price-new" {{ coreshop_test_html_attribute('product-unit-price-' ~ additionalUnit.unit.name, additionalUnitPrice) }}>
                                {{ additionalUnitPrice }}
                            </span>
                            {% if additionalUnit.conversionRate > 1 %}
                                <span class="badge badge-secondary">including {{ additionalUnit.conversionRate }} {{ defaultUnitDefinition.unit.translation(app.request.locale).fullLabel }}</span>
                            {% endif %}
                        </li>
                    {% endfor %}
                </ul>
            </div>
        </div>
    {% endif %}
{% endmacro %}
