<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/**
 * Grouped product data template
 *
 * @var $block \Magento\Catalog\Block\Product\View\BaseImage
 * @var $block \Magento\GroupedProduct\Block\Product\View\Type\Grouped
 */
?>
<?php $block->setPreconfiguredValue(); ?>
<?php $_product = $block->getProduct(); ?>
<?php $_associatedProducts = $block->getAssociatedProducts(); ?>
<?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>

<?php
//MNM
$salesBlock =   $this->getLayout()
                    ->createBlock('Magento\Catalog\Block\Product\ProductList\Item\Block')
                    ->setTemplate('MNM_Spitzner::product_sale_label.phtml');
$block->setChild('sale_label', $salesBlock);
//MNM
?>

<div class="table-wrapper grouped">
    <div class="table data grouped" id="super-product-table">
        <?php if ($_hasAssociatedProducts): ?>
        <?php foreach ($_associatedProducts as $_item): ?>
        <div class="item">
<?php //MNM ?>
                    <strong class="product-item-name"><?= __('Inhalt').': '.$block->escapeHtml(str_replace('1000ml', '1L', $_item->getAttributeText('spi_inhalt'))) ?></strong>
                    <?php $salesBlock->setProduct($_item);
                          echo $block->getChildHtml('sale_label', false); ?>
<?php //MNM ?>
                    <?php if ($block->getCanShowProductPrice($_product)): ?>
                        <?php if ($block->getCanShowProductPrice($_item)): ?>
                            <?= /* @escapeNotVerified */ $block->getProductPrice($_item) ?>
                        <?php endif; ?>
                     <?php endif; ?>

                <?php if ($_product->isSaleable()): ?>

                    <?php if ($_item->isSaleable()) : ?>
                        <div class="control qty">
                            <input type="number"
                                   name="super_group[<?= /* @escapeNotVerified */ $_item->getId() ?>]"
                                   data-selector="super_group[<?= /* @escapeNotVerified */ $_item->getId() ?>]"
                                   value="<?= /* @escapeNotVerified */ $_item->getQty() * 1 ?>"
                                   title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                                   class="input-text qty"
                                   data-validate="{'validate-grouped-qty':'#popup_content #super-product-table'}"
                                   data-errors-message-box="#popup_content #validation-message-box"/>
                        </div>
                    <?php endif; ?>

                <?php endif; ?>
            <?php if ($block->getCanShowProductPrice($_product)
                && $block->getCanShowProductPrice($_item)
                && trim($block->getProductPriceHtml(
                    $_item,
                    \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE
                ))): ?>
                <tr class="row-tier-price">
                    <td colspan="2">
                        <?= $block->getProductPriceHtml(
                            $_item,
                            \Magento\Catalog\Pricing\Price\TierPrice::PRICE_CODE
                        ) ?>
                    </td>
                </tr>
            <?php endif; ?>
        </div>
        <?php endforeach; ?>
        <?php else: ?>
        <tbody>
            <tr>
                <td class="unavailable"
                    colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>">
                    <?= /* @escapeNotVerified */ __('No options of this product are available.') ?>
                </td>
            </tr>
        </tbody>
        <?php endif; ?>
    </div>
</div>
<div id="validation-message-box"></div>
