Add quantity 2 when adding to cart from product view page.

For only one product because it calls 2-time post request for one product.

After clearing cache and checking and some time that works, but again that problem comes in other product.

  • Have you customize anything or extended any js ? – Codrain Technolabs Pvt Ltd Apr 22 '16 at 11:39
  • have you got this answer @user15917 – Devidas Oct 27 '18 at 7:23

The \Magento\Checkout\Controller\Cart\Add::execute() method has support for the qty request param. Try adding a new hidden input named qty and value of 2 in the add-to-cart form template file.

Maybe there's a more elegant way of doing this, but I don't know about it yet.

  • 1
    I have added this code: <script type="text/x-magento-init"> { "#product_addtocart_form": { "Magento_Catalog/product/view/validation": { "radioCheckboxClosest": ".nested" }, "catalogAddToCart": { "addToCartButtonTextDefault": "<?php echo __('Add to Cart'); ?>", "addToCartButtonTextWhileAdding": "<?php echo __('Adding...'); ?>", "addToCartButtonTextAdded": "<?php echo __('Added'); ?>" } } } </script> in vendor/magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml – user15917 Apr 26 '16 at 11:50

from addtocart.phtml

<input type="number" 
    value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
    title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" 
    class="input-text qty" data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"  />

change value to "2"


Hello it happen with me.

Solution for that:addtocart intilize two times on page so find out and remove it

Your Answer

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