{% sw_extends '@fourtwosixAttributeBadges/storefront/component/product/card/box-standard.html.twig' %}
{# @fourtwosix-edit: RD addedd triangles badge }} #}
{% 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.translated.name|length <= 5 %}
{% set badgeLengthClass = "5" %}
{% elseif badge.translated.name|length === 6 %}
{% set badgeLengthClass = "6" %}
{% elseif badge.translated.name|length >= 7 %}
{% set badgeLengthClass = "7" %}
{% endif %}
{% 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.group.translated.name ~ ': ' ~ badge.translated.name
}
} %}
{% elseif badge.group.translated.customFields.fts_property_group_custom_graphics_option %}
<div class="dynamic-badge-box arrow-badge"
data-toggle="tooltip"
data-placement="top"
title="{{ badge.group.translated.name }}: {{ badge.translated.name }}">
<div class="option-label length-{{ badgeLengthClass }}">
{{ badge.translated.name|length > 7 ? badge.translated.name|slice(0, 7) ~ '...' : badge.translated.name }}
</div>
</div>
{% else %}
<div class="dynamic-badge-box"
data-toggle="tooltip"
data-placement="top"
title="{{ badge.group.translated.name }}: {{ badge.translated.name }}">
<div class="option-label length-{{ badgeLengthClass }}">
{{ badge.translated.name|length > 7 ? badge.translated.name|slice(0, 7) ~ '...' : badge.translated.name }}
</div>
</div>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
</div>
{{block('component_product_box_info', '@zenitPlatformStratus/storefront/component/product/card/box-standard.html.twig')}}
{% endblock %}