2

I want to change quantity textbox to quantity dropdown on product page. I found solutions that work for magento 1 not for magento 2.

There is less information/doc about magento 2. It's being very difficult to customize magento 2.

Can anyone help me how i can do this.

Thanks in advance.

6
0

According to this file module-catalog/view/frontend/templates/product/view/addtocart.phtml you can try just add to your select id and name from default input

<select id="qty" name="qty" class="input-text qty"></select>
0

You have to override the below file in your theme or custom module.

vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml

After overriding, you need to change the input to select as I do below.

<div class="field qty">
            <label class="label" for="qty"><span><?= $block->escapeHtml(__('Qty')) ?></span></label>
            <div class="control">
                <select name="qty" id="qty" class="input-text qty" data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>">
                    <?php for ($i=1; $i < 50; $i++) :?>
                        <option value="<?= $i?>"><?= $i?></option>
                    <?php endfor;?>
                </select>
            </div>
        </div>

After that clear cache and check. Let me know if you still facing any issues.

Thanks.

Your Answer

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.