0
votes

I have a grid off products in on my category page that include an "add to cart" button below each product image. I have edited the layout of this grid via the list.phtml file. How would I add a quantity input box next to "add to cart" ?

2

2 Answers

1
votes

If only simple product is involved, it is not difficult. But for all the products type, it's really complicated.

Hope the following snippets can be helpful to you:

<div class="product-list">
  <div class="product">
    <form class="product-<?php echo $_product_id?>" action="<?php // add to cart url?>">
      <input type="hidden" name="product" value="<?php echo $_product_id; ?>">
      <input type="text" name="qty">
      <button class="add-to-cart" value="add to cart">
    </form>
  </div>
</div>
<script>
   jQuery(function() {
      jQuery('.add-to-cart').click(function() {
        jQuery(this).parent().submit();
      });
   });
</script>

By the way, I think if you have already implement this, AJAX may give great improvement to the user experience, and the code will need slight changes.

0
votes

You may first need to know how the form will be submitted. There's a form when submit the "add to cart" action.

As answered by Ram Les, you need to add the "qty" input box into the form. So when you click add to cart, the form with the Qty information will be submit to controller, from there, the controller will handle how many qty of the products to be added.

Hope this help.