{% sw_extends '@Storefront/storefront/component/product/card/action.html.twig' %}
{% block component_product_box_action_inner %}
{% set id = product.id %}
<div class="product-action">
{% set isAvailable = not product.isCloseout or (product.availableStock >= product.minPurchase) %}
{% set displayFrom = product.calculatedPrices.count > 1 %}
{# % set displayBuyButton = isAvailable and not displayFrom and product.childCount <= 0 % #}
{% set displayBuyButton = isAvailable and product.childCount <= 0 %}
{% if displayBuyButton and config('core.listing.allowBuyInListing') %}
{% block component_product_box_action_buy %}
{# @var product \Shopware\Core\Content\Product\SalesChannel\SalesChannelProductEntity #}
<form action="{{ path('frontend.checkout.line-item.add') }}"
method="post"
class="buy-widget"
data-add-to-cart="true">
{% block component_product_box_action_buy_csrf %}
{{ sw_csrf('frontend.checkout.line-item.add') }}
{% endblock %}
{% block component_product_box_action_form %}
{% block component_product_box_action_buy_redirect_input %}
{# fallback redirect back to detail page is deactivated via js #}
<input type="hidden"
name="redirectTo"
value="frontend.detail.page">
<input type="hidden"
name="redirectParameters"
data-redirect-parameters="true"
value='{"productId": "{{ product.id }}"}'>
{% endblock %}
{% block page_product_detail_buy_product_buy_info %}
<input type="hidden"
name="lineItems[{{ id }}][id]"
value="{{ id }}">
<input type="hidden"
name="lineItems[{{ id }}][referencedId]"
value="{{ id }}">
<input type="hidden"
name="lineItems[{{ id }}][type]"
value="product">
<input type="hidden"
name="lineItems[{{ id }}][stackable]"
value="1">
<input type="hidden"
name="lineItems[{{ id }}][removable]"
value="1">
{# <input type="hidden"
name="lineItems[{{ id }}][quantity]"
value="{{ product.minPurchase }}"> #}
{% endblock %}
{% block page_product_detail_product_buy_meta %}
<input type="hidden"
name="product-name"
value="{{ product.translated.name }}">
{% endblock %}
{% block page_product_detail_product_buy_button %}
{# @deprecated tag:v6.5.0 - Bootstrap v5 removes `btn-block` class, use `d-grid` wrapper instead #}
<div class="calc-block">
{# { dump(product.calculatedPrice.unitPrice) } #}
{# { dump(product.calculatedCheapestPrice.unitPrice) } #}
{# { dump(product.calculatedPrices.elements[0].unitPrice) } #}
{% set purchasePrice = 0 %}
{% if product.calculatedPrice.unitPrice and product.calculatedPrice.unitPrice != 0 %}
{% set purchasePrice = product.calculatedPrice.unitPrice %}
{% endif %}
{% if product.calculatedPrices.elements[0].unitPrice and product.calculatedPrice.unitPrice != 0 %}
{% set purchasePrice = product.calculatedPrices.elements[0].unitPrice %}
{% endif %}
{% if product.calculatedCheapestPrice.unitPrice and product.calculatedCheapestPrice.unitPrice != 0 %}
{% set purchasePrice = product.calculatedCheapestPrice.unitPrice %}
{% endif %}
<input type="hidden" name="minPurchase" class="calc-min-purchase" value="{{ product.minPurchase }}" />
<input type="hidden" name="maxPurchase" class="calc-max-purchase" value="{{ product.maxPurchase }}" />
<input type="hidden" name="purchaseStep" class="calc-purchase-step" value="{{ product.purchaseSteps }}" />
{% if product.calculatedPrices|length > 1 %}
{% set breakloop = false %}
{% for price in product.calculatedPrices %}
{% if not breakloop %}
{% set abStaffel = product.minPurchase %}
{% if loop.index > 1 %}
{% set idx = loop.index - 2 %}
{% set pArr = product.calculatedPrices %}
{% set abStaffel = pArr.elements[idx].quantity + 1 %}
{% if abStaffel >= product.minPurchase %}
{% set purchasePrice = price.unitPrice %}
{% set breakloop = true %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% set totalPrice = product.minPurchase * purchasePrice %}
<input type="hidden" name="purchasePrice" class="calc-purchase-price" value="{{ purchasePrice }}" />
<input type="hidden" name="totalPrice" class="calc-purchase-total" value="{{ totalPrice }}" />
<div class="calc-result-block">
<span class="calc-cur-amount">{{ product.minPurchase }}</span> x
<span class="calc-cur-price">{{ purchasePrice|number_format(2,",",".") }} €</span> =
<span class="calc-cur-total">{{ totalPrice|number_format(2,",",".") }} €{{ "general.star"|trans|sw_sanitize }}</span>
</div>
{% if feature('v6.5.0.0') %}
<div class="d-grid">
<button class="btn btn-buy"
title="{{ "listing.boxAddProduct"|trans|striptags }}">
{{ "listing.boxAddProduct"|trans|sw_sanitize }}
</button>
</div>
{% else %}
<button type="button" class="btn btn-primary calc-btn calc-btn-down">-</button>
<input name="lineItems[{{ id }}][quantity]"
value="{{ product.minPurchase }}"
class="product-details-quantity-select calc-input-qty">
<button type="button" class="btn btn-primary calc-btn calc-btn-up">+</button>
<button class="btn btn-buy"
title="{{ "listing.boxAddProduct"|trans|striptags }}">
{% sw_icon 'cart' %}
</button>
{% endif %}
</div>
{% endblock %}
{% endblock %}
</form>
{% endblock %}
{% else %}
{% block component_product_box_action_detail %}
{# @deprecated tag:v6.5.0 - Bootstrap v5 removes `btn-block` class, use `d-grid` wrapper instead #}
{% if feature('v6.5.0.0') %}
<div class="d-grid">
<a href="{{ seoUrl('frontend.detail.page', {'productId': id}) }}"
class="btn btn-light"
title="{{ "listing.boxProductDetails"|trans|striptags }}">
{{ "listing.boxProductDetails"|trans|sw_sanitize }}
</a>
</div>
{% else %}
<div class="calc-result-block"> </div>
<a href="{{ seoUrl('frontend.detail.page', {'productId': id}) }}"
class="btn btn-block btn-light"
title="{{ "listing.boxProductDetails"|trans|striptags }}">
{{ "listing.boxProductDetails"|trans|sw_sanitize }}
</a>
{% endif %}
{% endblock %}
{% endif %}
</div>
{% block component_product_box_action_meta %}
<input type="hidden"
name="product-name"
value="{{ product.translated.name }}">
<input type="hidden"
name="product-id"
value="{{ id }}">
{% endblock %}
{% endblock %}