{% sw_extends '@Storefront/storefront/page/product-detail/buy-widget-form.html.twig' %}
{% block page_product_detail_buy_quantity_container %}
{% set purchasePrice = 0 %}
{% set cheapestPrice = 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 cheapestPrice = product.calculatedCheapestPrice.unitPrice %}
{% endif %}
{% 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 %}
<div class="calc-result-block col-6">
<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>
<div class="col-6">
{#
Purchase: {{ purchasePrice }} | Unit: {{ price.unitPrice }} | Cheapest: {{ cheapestPrice }}
#}
</div>
<div class="col-6 calc-block">
{% block page_product_detail_buy_quantity %}
<button type="button" class="btn btn-primary calc-btn calc-btn-down">-</button>
<input name="lineItems[{{ product.id }}][quantity]" value="{{ product.minPurchase }}"
class="product-detail-quantity-select calc-input-qty"
/>
<button type="button" class="btn btn-primary calc-btn calc-btn-up">+</button>
<input type="hidden" name="minPurchase" class="calc-min-purchase" value="{{ product.minPurchase }}" />
<input type="hidden" name="purchaseStep" class="calc-purchase-step" value="{{ product.purchaseSteps }}" />
<input type="hidden" name="maxPurchase" class="calc-max-purchase" value="{{ product.maxPurchase }}" />
<input type="hidden" name="curPrice" class="calc-purchase-price" value="{% if purchasePrice %}{{ purchasePrice }}{% else %}{{ price.unitPrice }}{% endif %}" />
<input type="hidden" name="totalPrice" class="calc-purchase-total" value="{{ totalPrice }}" />
{% endblock %}
</div>
{% endblock %}
{% block page_product_detail_buy_button_container %}
<div class="col-6">
{% block page_product_detail_buy_button %}
{{ parent() }}
{% endblock %}
</div>
{% endblock %}