How to add quantity box on product list page in magento

Hello Friend, There are two ways to display quantity box on product list page.  

First way to put quantity box on list page:

Find below code on app/design/frontend/YourTheme/YourPackage/template/catalog/product/list.phtml file
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
Put below code instead of above code:
<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
    <?php if(!$_product->isGrouped()): ?>
        <label for="qty"><?php echo $this->__('Qty') ?>:</label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" class="input-text qty"/>
    <?php endif; ?>
    <button type="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>
 

Second way to put quantity box on list page:

Find below code on app/design/frontend/YourTheme/YourPackage/template/catalog/product/list.phtml file
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
Put below code instead of above code:
<?php $product_id=$_product->getId() ?>
<?php $base_url=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="<?php echo $product_id ?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty"></input>
<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onClick="addToCart('<?php echo $product_id ?>','<?php echo $base_url?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
and also put below js at the end of file.
<script type="text/javascript">
function addToCart(pid,purl)
{
	var qty=document.getElementById(pid).value;
	var action=purl+"checkout/cart/add/product/"+pid+"/qty/"+qty;
	window.location=action;
}
</script>
  Thanks,
Pritesh Pritesh

Pritesh Pethani

Request a Quote!!

Share your concept and we will return to you within 24 hours. Let us work out the best software solution for you!

Let's Start
Whatspp