{% import "@SyliusShop/Common/Macro/money.html.twig" as money %}
{# Variants as accordion with inline image, stock and add-to-cart #}
{% for key, variant in product.enabledVariants %}
{% set channelPricing = variant.getChannelPricingForChannel(sylius.channel) %}
{% set appliedPromotions = channelPricing.appliedPromotions|map(promotion => ({'label': promotion.label, 'description': promotion.description})) %}
{% set days = sylius.channel.channelPriceHistoryConfig.lowestPriceForDiscountedProductsCheckingPeriod %}
{% set hasLowestPrice = variant|sylius_has_lowest_price({'channel': sylius.channel})%}
{% set hasDiscount = variant|sylius_has_discount({'channel': sylius.channel}) %}
{% set available = sylius_inventory_is_available(variant) %}
{# Variant image resolution #}
{% set variantImage = null %}
{% if variant.images|length > 0 %}
{% for image in variant.images %}
{% if variantImage is null and image.path is not empty %}
{% set variantImage = image %}
{% endif %}
{% endfor %}
{% endif %}
{% if variantImage is null %}
{% for image in product.images %}
{% if variantImage is null and image.productVariants is defined and image.path is not empty %}
{% for linkedVariant in image.productVariants %}
{% if variantImage is null and linkedVariant.id is defined and linkedVariant.id == variant.id %}
{% set variantImage = image %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% set hasVariantImage = variantImage is not null %}
{% set variantImageSrc = hasVariantImage ? variantImage.path|imagine_filter('sylius_shop_product_thumbnail') : null %}
{% set variantImageOriginal = hasVariantImage ? variantImage.path|imagine_filter('sylius_shop_product_original') : null %}
{# Stock calculation (approx): onHand - onHold when tracked #}
{% set isTracked = variant.tracked is defined ? variant.tracked : true %}
{% set onHand = variant.onHand is defined ? variant.onHand : null %}
{% set onHold = variant.onHold is defined ? variant.onHold : 0 %}
{% set stockQty = isTracked and onHand is not null ? (onHand - onHold) : null %}
{% set isOpen = form.cartItem.variant[key].vars.checked %}
{% set _attr = {'class': 'd-none'} %}
{% if not available %}
{% set _attr = _attr|merge({'disabled': true}) %}
{% endif %}
{{ form_widget(form.cartItem.variant[key], {
'attr': _attr,
'label': false,
'label_attr': {'class': 'd-none'}
}) }}
{# Header: clickable to select and toggle #}
{# Body: image (bigger), stock and controls #}
{# Left column: delivery info (no frame), stock, quantity, button all stacked vertically #}
{# Delivery information from associated suppliers (plain, no label) #}
{% for link in variant.suppliers %}
{% set info = link.supplier.deliveryInformation %}
{% if info %}
{{ info|nl2br }}
{% endif %}
{% endfor %}
{% if available %}
{% if stockQty is not null %}
{{ stockQty }} en stock
{% else %}
En stock
{% endif %}
{% else %}
Rupture
{% endif %}
{# Right column: image (shown only if the variant has its own) #}
{% if hasVariantImage %}
{% endif %}