how to add quantity box on product list page in opencart

1. Modify the add to cart function in Catalog/view/javascript/common.js

 

function addToCart(product_id, el) {
if ($(el).parent().children('input[name="quantity"]').val() != 'undefined') {
quantity = $(el).parent().children('input[name="quantity"]').val();
} else {
quantity = 1;
}

$.ajax({
url: 'index.php?route=checkout/cart/update',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + quantity,

 

2. modify the product or category list page template file

Change this line
 

<div class="cart"><a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><span><?php echo $button_cart; ?></span></a></div>

To

 

<div class="cart"><?php echo $text_quantity; ?> <input type="text" size="3" id="quantity-<?php echo $product['product_id']; ?>" name="quantity" value="1" /> <a onclick="addToCart('<?php echo $product['product_id']; ?>', this);" class="button"><span><?php echo $button_cart; ?></span></a></div>

 

Leave a Comment