0

I added dropdown for product qty box in addtocart.phtml like below:

<div class="field qty">
        <label class="label" for="qty"><span><?php /* @escapeNotVerified */ echo __('Qty') ?></span></label>               
        <select name="qty" id="qty" title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" 
               class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>">
               <?php $i = 1 ; ?>
                <?php 
                 while( $i < 500) { ?>
                    <option value="<?php echo $block->getProductDefaultQty() * $i; ?>"><?php echo $block->getProductDefaultQty() * $i; ?></option>
                    <?php $i++; ?>
                 <?php } ?>
        </select>

    </div>

But I also want to implement same in updatecart.html in magento 2. How to do that?

enter image description here

7
1

You are doing correctly.

First copy updatecart.phtml file from vendor/magento/module-checkout/view/frontend/templates/cart/item/configure/updatecart.phtml file and put it in your theme at app/design/frontend/[Vendor]/[Theme]/Magento_Checkout/templates/cart/item/configure/updatecart.phtml.

code as per requirement.

Just replace div in that file

<div class="field qty">
   <label class="label" for="qty">
       <span><?= /* @escapeNotVerified */ __('Qty') ?></span>
   </label>
   <div class="control">
       <select name="qty" id="qty" title="<?php echo __('Qty') ?>" 
            class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>">
                <?php $i = 1 ; ?>
                <?php 
                while( $i < 500) { ?>
                    <option value="<?php echo $block->getProductDefaultQty() * $i; ?>"><?php echo $block->getProductDefaultQty() * $i; ?></option>
                    <?php $i++; ?>
                <?php } ?>
        </select>
    </div>
</div>
2
  • Now it is showing the qty box values as 3,6,9,12 in that way. May 18 '20 at 4:37
  • getProductDefaultQty gets the previously entered qty value. May 18 '20 at 4:49

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.