0

I have been successful in adding code to the file addtocart.phtml to have increment and decrement. I had read to add the same code to grouped.phtml to have the option on the grouped page. the boxes are there however when I click on one it changes all the products on the page and the boxes are on top and bottom of the quantity not on the sides like on the product page. there must be a simple way to fix this.

this is a screen shot

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

/**
 * 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; ?>

<div class="table-wrapper grouped">
    <table class="table data grouped"
           id="super-product-table"
           data-mage-init='{ "Magento_GroupedProduct/js/product-ids-resolver": {} }'>
        <caption class="table-caption"><?= $block->escapeHtml(__('Grouped product items')) ?></caption>
        <thead>
        <tr>
            <th class="col item" scope="col"><?= $block->escapeHtml(__('Product Name')) ?></th>
            <?php if ($_product->isSaleable()) : ?>
                <th class="col qty" scope="col"><?= $block->escapeHtml(__('Qty')) ?></th>
            <?php endif; ?>
        </tr>
        </thead>

        <?php if ($_hasAssociatedProducts) : ?>
        <tbody>
            <?php foreach ($_associatedProducts as $_item) : ?>
            <tr>
                <td data-th="<?= $block->escapeHtml(__('Product Name')) ?>" class="col item">
                    <strong class="product-item-name"><?= $block->escapeHtml($_item->getName()) ?></strong>
                    <?php if ($block->getCanShowProductPrice($_product)) : ?>
                        <?php if ($block->getCanShowProductPrice($_item)) : ?>
                            <?= /* @noEscape */ $block->getProductPrice($_item) ?>
                        <?php endif; ?>
                        <?php endif; ?>
                </td>
                <?php if ($_product->isSaleable()) : ?>
                <td data-th="<?= $block->escapeHtml(__('Qty')) ?>" class="col qty">
                    <?php if ($_item->isSaleable()) : ?>
                    <div class="control qty">
                        <input type="number"
                               name="super_group[<?= $block->escapeHtmlAttr($_item->getId()) ?>]"
                               data-selector="super_group[<?= $block->escapeHtmlAttr($_item->getId()) ?>]"
                               value="<?= $block->escapeHtmlAttr($_item->getQty() * 1) ?>"
                               title="<?= $block->escapeHtmlAttr(__('Qty')) ?>"
                               class="input-text qty"
                               data-validate="{'validate-grouped-qty':'#super-product-table'}"
                               data-errors-message-box="#validation-message-box"/>
                    </div>
<div class="field qty">
        <label class="label" for="qty"><span><?= /* @escapeNotVerified */ __('Qty') ?></span></label>
        <script type="text/x-magento-init">
            {
                ".control button": {
                    "Magento_Catalog/js/view/product/qty": {}
                }
            }
        </script>
        <div class="control">
            <button class="decreaseQty" data-product-item="<?= /* @escapeNotVerified */ $_product->getId() ?>">-</button>
            <input type="number"
                   name="qty"
                   id="qty"
                   value="<?= /* @escapeNotVerified */ $block->getProductDefaultQty() * 1 ?>"
                   title="<?= /* @escapeNotVerified */ __('Qty') ?>"
                   class="input-text qty"
                   data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
                   data-product-item="<?= /* @escapeNotVerified */ $_product->getId() ?>"
                   />
            <button class="increaseQty" data-product-item="<?= /* @escapeNotVerified */ $_product->getId() ?>">+</button>
        </div>
    </div>
                <?php else : ?>
                    <div class="stock unavailable" title="<?= $block->escapeHtmlAttr(__('Availability')) ?>">
                        <span><?= $block->escapeHtml(__('Out of stock')) ?></span>
                    </div>
                <?php endif; ?>
                </td>
                <?php endif; ?>
            </tr>
                <?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; ?>
        <?php endforeach; ?>
        </tbody>
        <?php else : ?>
        <tbody>
            <tr>
                <td class="unavailable"
                    colspan="<?php if ($_product->isSaleable()) : ?>4<?php else : ?>3<?php endif; ?>">
                    <?= $block->escapeHtml(__('No options of this product are available.')) ?>
                </td>
            </tr>
        </tbody>
        <?php endif; ?>
    </table>
</div>
<div id="validation-message-box"></div>
| improve this question | | | | |
New contributor
Jeff Treece is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • looks like you are missing some closing tags for some elements html, validate your code and fix it :) – Gosu Przmak May 21 at 5:47
0

For grouped product, You have to add the code in Magento_GroupedProduct/templates/product/view/type/grouped.phtml file.

| improve this answer | | | | |

Your Answer

Jeff Treece is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.