{% sw_extends '@Storefront/storefront/component/product/card/badges.html.twig' %}
{% block component_product_badges_discount %}
{% if product.available == false %}
<div class="badge badge-info badge-soldout">
<span>{{"listing.boxLabelSoldout"|trans|sw_sanitize}}</span>
</div>
{% endif %}
{% set badgeExtension = product.getExtension("doncarneProductBadge").all()|first %}
{% if badgeExtension %}
{% if badgeExtension.media %}
<div class="badge" style="background:{{badgeExtension.colorHexCode}};width:auto;height:auto;">
<img style="height:auto;width:100%;max-width:92px;object-fit:contain;" src="{{badgeExtension.media.url}}" alt="{{badgeExtension.media.alt}}">
</div>
{% else %}
<div class="badge" style="background:{{badgeExtension.colorHexCode}}">
<span>{{ badgeExtension.translated.name }}</span>
</div>
{% endif %}
{% endif %}
{% set price = product.calculatedPrice %}
{% if product.calculatedPrices.count > 0 %}
{% set price = product.calculatedPrices.last %}
{% endif %}
{% set listPrice = price.listPrice.percentage > 0 %}
{% set hasRange = product.calculatedPrices.count > 1 %}
{# DONCARNE-104: *DO NOT* show discount badge for beef club customers #}
{% if not (context.customer and context.customer.groupId == doncarneConfig.beefClubCustomerGroup) %}
{% if listPrice and not hasRange and not badgeExtension %}
<div class="badge badge-danger badge-discount">
<span>{{"listing.boxLabelDiscount"|trans|sw_sanitize}}</span>
</div>
{% endif %}
{% endif %}
{% endblock %}