|
{% if p %}
{% set basePrice = p.priceTtc ?? 0 %}
{% set finalPrice = basePrice %}
{% set promoPercent = 0 %}
{% if p.promotion
and p.promotion.isEnabled
and p.promotion.startAt
and p.promotion.endAt
and ('now'|date('U')) >= (p.promotion.startAt|date('U'))
and ('now'|date('U')) <= (p.promotion.endAt|date('U')) %}
{% set discountType = (p.promotion.discountType ?? '')|lower %}
{% set discountValue = p.promotion.discountValue ?? 0 %}
{% if discountType in ['percentage', 'percent', 'pourcentage'] %}
{% set promoPercent = discountValue %}
{% set finalPrice = basePrice - (basePrice * promoPercent / 100) %}
{% elseif discountType in ['fixed', 'amount', 'montant'] %}
{% set finalPrice = basePrice - discountValue %}
{% if finalPrice < 0 %}{% set finalPrice = 0 %}{% endif %}
{% if basePrice > 0 %}
{% set promoPercent = ((basePrice - finalPrice) * 100 / basePrice) %}
{% endif %}
{% endif %}
{% endif %}
{% if finalPrice < basePrice %}
{{ finalPrice|number_format(3, '.', ' ') }}
{{ basePrice|number_format(3, '.', ' ') }}
-{{ promoPercent|number_format(0, '.', ' ') }}%
{% else %}
{{ basePrice|number_format(3, '.', ' ') }}
{% endif %}
{% else %}
0.000
{% endif %}
|