Magento: Adding +/- quantity increment buttons in list.phtml

Magento: Adding +/- quantity increment buttons in list.phtml

August 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Adding +/- quantity increment buttons in list.phtml

Solving Quantity Increment Issues for Magento List View

You’ve made great progress adding quantity increment buttons (+/-) to your product list view page in Magento. The buttons are visible and functional, updating the quantity field as expected. However, you’re rightfully concerned that clicking “Add to Cart” still only adds a single item regardless of the adjusted quantity.

To fix this issue, we need to modify the JavaScript code and ensure it communicates effectively with the “Add to Cart” button on your Magento page. Here’s how to achieve this:

1. Update Your JavaScript Code

Currently, your JavaScript updates the quantity field but doesn’t pass the updated value to the “Add to Cart” function. We’ll need to modify the setLocation function call in the “Add to Cart” button onclick event.

First, let’s add an ID or class to the quantity input field for easy selection:

<div class="quantity">
  <input type="text" name="qty" id="product-<?php echo $_product->getId() ?>" maxlength="12"
         value="<?php echo $this->getMinimalQty($_product) ?>"
         title="<?php echo $this->__('Qty') ?>"
         class="input-text qty"/>
</div> <!-- /.quantity -->

Then, update your JavaScript:

<script type="text/javascript">
  jQuery("div.quantity").append('<input type="button" value="+1" id="add-<?php echo $_product->getId() ?>" class="plus" />')
    .prepend('<input type="button" value="-1" id="minus-<?php echo $_product->getId() ?>" class="minus" />');

  jQuery(".plus").click(function()
  {
    var currentVal = parseInt(jQuery(this).prev(".qty").val());
    if (!currentVal || currentVal=="" || isNaN(currentVal)) currentVal = 0;
    jQuery(this).prev(".qty").val(currentVal + 1);
  });

  jQuery(".minus").click(function()
  {
    var currentVal = parseInt(jQuery(this).next(".qty").val());
    if (isNaN(currentVal)) currentVal = 0;
    if (currentVal > 0)
    {
      jQuery(this).next(".qty").val(currentVal - 1);
    }
  });
</script>

2. Update the “Add to Cart” Button Script

Now, let’s modify the “Add to Cart” button script to include the updated quantity:

<p><button type="button"
           title="<?php echo $this->__('Add to Cart') ?>"
           class="button btn-cart">
  <span>
    <span><?php echo $this->__('Add to Cart') ?></span>
  </span>

  <!-- Update the URL with the quantity -->
  <?php echo $this->getAddToCartUrl($_product, array('qty' => jQuery('#product-<?php echo $_product->getId() ?>').val())) ?>

</button></p>

3. Debugging

Ensure that your JavaScript is properly loaded and the IDs/Classes are correctly assigned to the quantity fields and buttons.

Read more about Magento’s core JavaScript functions here for a deeper understanding of how the “Add to Cart” process works.

Conclusion

With these modifications, the “Add to Cart” button should now recognize and add the specified quantity from the updated field. This solution maintains Magento’s core functionality while allowing you to customize the user experience with your own increment/decrement buttons.

Remember, it’s crucial to test this on various browsers and scenarios to ensure the functionality is consistent across all user devices and edge cases.

If you’re ever stuck or need further assistance in customizing your Magento store, feel free to explore our Magento development services at Laravel Company. Our team of experienced developers specializes in helping businesses make the most out of their e-commerce platforms.

Checkout Catalog Database Themes

Our network