<?php
/**
 * Maho
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2023 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
 ?>
<?php /** @var Mage_Adminhtml_Block_Catalog_Product_Composite_Fieldset_Grouped $this */ ?>
<?php $_skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck(); ?>
<div id="catalog_product_composite_configure_fields_grouped" class="grid <?= $this->getIsLastFieldset() ? 'last-fieldset' : '' ?>">
    <h4><?= Mage::helper('catalog')->__('Associated Products') ?></h4>
    <div class="product-options">
        <?php $_product = $this->getProduct(); ?>
        <?php $this->setPreconfiguredValue(); ?>
        <?php $_associatedProducts = $this->getAssociatedProducts(); ?>
        <?php $_hasAssociatedProducts = count($_associatedProducts) > 0; ?>
        <?php if ((!$_product->isAvailable() && !$_skipSaleableCheck) || !$_hasAssociatedProducts): ?>
            <p class="availability out-of-stock"><?= Mage::helper('catalog')->__('Availability:') ?> <span><?= Mage::helper('catalog')->__('Out of stock') ?></span></p>
        <?php endif ?>
        <table class="data-table grouped-items-table" id="super-product-table">
            <col />
            <col />
            <col />
            <col />
            <col width="1" />
            <thead>
                <tr "class="headings">
                    <th><?= Mage::helper('catalog')->__('ID') ?></th>
                    <th><?= Mage::helper('catalog')->__('SKU') ?></th>
                    <th><?= Mage::helper('catalog')->__('Product Name') ?></th>
                    <?php if ($this->getCanShowProductPrice($_product)): ?>
                    <th class="a-right"><?= Mage::helper('catalog')->__('Price') ?></th>
                    <?php endif ?>
                    <?php if ($_product->isSaleable() || $_skipSaleableCheck): ?>
                    <th class="a-center"><?= Mage::helper('catalog')->__('Qty') ?></th>
                    <?php endif ?>
                </tr>
            </thead>
            <tbody>
            <?php if ($_hasAssociatedProducts): ?>
                <?php $i = 0 ?>
            <?php foreach ($_associatedProducts as $_item): ?>
                <?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
                <tr class="<?= (++$i % 2) ? 'even' : 'odd' ?>">
                    <td><?= $_item->getId() ?></td>
                    <td><?= $this->escapeHtml($_item->getSku()) ?></td>
                    <td><?= $this->escapeHtml($_item->getName()) ?></td>
                    <?php if ($this->getCanShowProductPrice($_product)): ?>
                    <td class="a-right">
                        <?php if ($this->getCanShowProductPrice($_item)): ?>
                        <?= $this->getPriceHtml($_item, true) ?>
                        <?php endif ?>
                    </td>
                    <?php endif ?>
                    <?php if ($_product->isSaleable() || $_skipSaleableCheck): ?>
                    <td class="a-center">
                    <?php if ($_item->isSaleable() || $_skipSaleableCheck) : ?>
                        <input type="text" name="super_group[<?= $_item->getId() ?>]" id="super_group[<?= $_item->getId() ?>]" maxlength="12" value="<?= $_item->getQty()*1 ?>" title="<?= Mage::helper('core')->quoteEscape(Mage::helper('catalog')->__('Qty')) ?>" class="input-text qty" />
                        <input type="hidden" value="1" price="<?= $this->getCurrencyPrice($_item->getPrice()) ?>" qtyId="super_group[<?= $_item->getId() ?>]" />
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?= $this->__('Out of stock') ?></span></p>
                    <?php endif ?>
                    </td>
                    <?php endif ?>
                </tr>
            <?php endforeach ?>
            <?php else: ?>
               <tr>
                   <td colspan="<?php if ($_product->isSaleable() || $_skipSaleableCheck): ?>4<?php else: ?>3<?php endif ?>"><?= Mage::helper('catalog')->__('No options of this product are available.') ?></td>
               </tr>
            <?php endif ?>
            </tbody>
        </table>
    </div>
</div>
