{% sw_extends '@Storefront/storefront/component/product/card/box-standard.html.twig' %}
{% block component_product_box_info %}
<div class="d-flex fourtwosix-badges">
{% set badgesMediaIds = [] %}
{% set propertiesBadge = [] %}
{% set configDefaultMedia = config('fourtwosixAttributeBadges.config.defaultMedia') %}
{# checks whether the property group has a customField attribute_badge #}
{% if product.sortedProperties != null %}
{% for x in product.sortedProperties|filter(x => x.translated.customFields.attribute_badges == true) -%}
{% set propertiesBadge = propertiesBadge|merge(x.options.elements) %}
{% endfor %}
{% if propertiesBadge %}
{% for badge in propertiesBadge %}
{% if badge.mediaId != null %}
{% set badgesMediaIds = badgesMediaIds|merge([badge.mediaId]) %}
{% else %}
{% set badgesMediaIds = badgesMediaIds|merge([configDefaultMedia]) %}
{% endif %}
{% endfor %}
{% set mediaCollection = searchMedia(badgesMediaIds, context.context) %}
{% for badge in propertiesBadge|sort((a, b) => a.position <=> b.position)|slice(0,8) %}
{% if badge.mediaId != null %}
{% set badgeMedia = mediaCollection.get(badge.mediaId) %}
{% sw_thumbnails 'product-detail-badge-thumbnails' with {
media: badgeMedia,
attributes: {
'class': 'img-fluid badgeImgListing',
'data-toggle' : 'tooltip',
'title': badge.translated.name
}
} %}
{% else %}
{% set badgeMedia = mediaCollection.get(configDefaultMedia) %}
{% sw_thumbnails 'product-detail-badge-thumbnails' with {
media: badgeMedia,
attributes: {
'class': 'img-fluid badgeImgListing',
'data-toggle' : 'tooltip',
'title': badge.translated.name
}
} %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
</div>
{{parent()}}
{% endblock %}