{% block wbfk_product_bundles %}
{% set bundleChildren = page.extensions.wbfkBundlesData ? page.extensions.wbfkBundlesData.bundleChildren : [] %}
{% set bundleParents = page.extensions.wbfkBundlesData ? page.extensions.wbfkBundlesData.bundleParents : [] %}
<div class="wbfk-product-bundles">
{% if bundleChildren.count > 0 %}
<h2>{{ 'wbfk-bundles.title-bundle-children' | trans }}</h2>
<div class="wbfk-product-bundles__bundle-child-grid">
{% for bundleChild in bundleChildren %}
<div class="wbfk-product-bundles__bundle-child">
{% if bundleChild.quantity > 0 %}
<div class="wbfk-product-bundles__bundle-child-quantity">
{{ bundleChild.quantity }}
</div>
{% endif %}
{% sw_include '@Storefront/storefront/component/product/card/box.html.twig' with {
'product': bundleChild.salesChannelChildProduct,
'layout': 'standard',
'displayMode': 'contain'
} %}
</div>
{% endfor %}
</div>
{% endif %}
{% if bundleParents.count > 0 %}
{% set visibleItemsByDefault = 3 %}
<h2>{{ 'wbfk-bundles.title-bundle-parents' | trans }}</h2>
<div class="wbfk-product-bundles__bundle-parent-list">
{% for bundleParent in bundleParents %}
{% if loop.index == (visibleItemsByDefault + 1) %}
<input type="checkbox"
id="wbfk-product-bundles__unfold-checkbox"
class="wbfk-product-bundles__unfold-checkbox">
<label class="wbfk-product-bundles__unfold-label btn outline-blue btn-block"
for="wbfk-product-bundles__unfold-checkbox">
{{ 'wbfk-bundles.unfold-more-bundles' | trans({'%itemCount': bundleParents.count - visibleItemsByDefault}) }}
</label>
{% endif %}
{% if loop.index > visibleItemsByDefault %}
<div class="wbfk-product-bundles__unfold-container">
{% endif %}
<div class="wbfk-product-bundles__bundle-parent">
<div class="wbfk-product-bundles__bundle-parent-summary">
<span class="wbfk-product-bundles__bundle-parent-name">{{ bundleParent.salesChannelProduct.name }}</span>
{% set totalChildrenPrice = 0 %}
{% set totalParentPrice = bundleParent.salesChannelProduct.calculatedCheapestPrice.unitPrice %}
{% for bundleChild in bundleParent.childBundleProducts %}
{% set totalChildrenPrice = totalChildrenPrice + (bundleChild.quantity * bundleChild.salesChannelChildProduct.calculatedCheapestPrice.unitPrice) %}
{% endfor %}
{% if totalChildrenPrice %}
{% set savedPercent = (1 - (totalParentPrice / totalChildrenPrice)) * 100 %}
{% else %}
{% set savedPercent = null %}
{% endif %}
<div class="wbfk-product-bundles__bundle-parent-price">
<div class="product-badges">
<div class="badge badge-danger badge-discount">
<span>%</span>
</div>
</div>
<div class="wbfk-product-bundles__bundle-parent-price-inner">
{% if savedPercent %}
<div class="wbfk-product-bundles__bundle-parent-price-savings">
{{ 'wbfk-bundles.bundle-parent-savings' | trans({'%totalChildrenPrice': (totalChildrenPrice|round(2)|currency), '%savedPercent': (savedPercent|round(2)) }) }}
</div>
{% endif %}
<div class="wbfk-product-bundles__bundle-parent-price-total">
{{ 'wbfk-bundles.bundle-parent-total' | trans({'%totalParentPrice': (totalParentPrice|currency) }) }}
</div>
</div>
</div>
{% sw_include '@Storefront/storefront/component/product/card/action.html.twig' with {
'product': bundleParent.salesChannelProduct
} %}
</div>
<div class="wbfk-product-bundles__bundle-child-grid wbfk-product-bundles__bundle-parent-children">
{% for bundleChild in bundleParent.childBundleProducts %}
<div class="wbfk-product-bundles__bundle-child">
{% if bundleChild.quantity > 0 %}
<div class="wbfk-product-bundles__bundle-child-quantity">
{{ bundleChild.quantity }}
</div>
{% endif %}
{% sw_include '@Storefront/storefront/component/product/card/box.html.twig' with {
'product': bundleChild.salesChannelChildProduct,
'layout': 'standard',
'displayMode': 'contain'
} %}
</div>
{% endfor %}
</div>
</div>
{% if loop.index > visibleItemsByDefault %}
{# Close div.wbfk-product-bundles__unfold-container #}
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
{% endblock %}