{% sw_extends '@Storefront/storefront/component/buy-widget/buy-widget-form.html.twig' %}
{% block buy_widget_buy_container %}
{% set buyable = product.available and product.calculatedMaxPurchase > 0 %}
<div class="buy-widget-container flex grid-gap-2">
<div class="{% if buyable %}grid-gap-2{% endif %} {% if config('core.cart.wishlistEnabled') %}{% endif %}">
{% if buyable %}
{% block buy_widget_buy_quantity_container %}
{% endblock %}
{% block buy_widget_buy_redirect_input %}
{{ parent() }}
{% endblock %}
{% block buy_widget_buy_product_buy_info %}
{{ parent() }}
{% endblock %}
{% block buy_widget_product_buy_meta %}
{{ parent() }}
{% endblock %}
{% endif %}
{% if config('core.cart.wishlistEnabled') %}
{% block buy_widget_wishlist %}
{% sw_include '@Storefront/storefront/component/product/card/wishlist.html.twig' with {
showText: false,
size: 'sm',
productId: product.id
} %}
{% endblock %}
{% endif %}
</div>
{% block buy_widget_buy_button %}
{# Custom code to check if all variants are OOS, if so: Set buyable to false #}
{% if buyable %}
{% if options is null %}
{% set options = page.product.children %}
{% endif %}
{% set allOut = true %}
{% for key, option in options %}
{% set outOfStock = option.stock <= 0 %}
{% if not outOfStock %}
{% set allOut = false %}
{% break %}
{% endif %}
{% endfor %}
{% if allOut %}
{% set buyable = false %}
{% endif %}
{% endif %}
{# End of custom code #}
<button class="btn btn-primary btn-block btn-primary w-full {% if not buyable %}disabled{% endif %}"
data-product-add-to-cart-button="true"
title="{% if buyable %}{{ "detail.addProduct"|trans|striptags }}{% else %}{{ "detail.soldOut"|trans|sw_sanitize }}{% endif %}"
aria-label="{% if buyable %}{{ "detail.addProduct"|trans|striptags }}{% else %}{{ "detail.soldOut"|trans|sw_sanitize }}{% endif %}"
{% if not buyable %}disabled="disabled"{% endif %}>
{% sw_icon 'cart-solid' style {'pack': 'hero', 'class': ' white w-5'} %}
{% if buyable %}
{{ "detail.addProduct"|trans|sw_sanitize }}
{% else %}
{{ "detail.soldOut"|trans|sw_sanitize }}
{% endif %}
</button>
{% endblock %}
</div>
{% endblock %}