Wednesday 21 November 2012

Quantity Box in the Category Products Listing Page in magento

Your Magento product ordering might seem a long process to some business owners, so we thought of making it simple, so that users can directly enter the quantity in the products listing area and click on ADD TO CART and checkout.
So, here is how you can do that.

Goto /app/design/frontend/default/your-theme/template/catalog/product/list.phtml
Open the file on a code editor and find this line,

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" onClick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>

Just replace it with,

<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) ?>" />
  <?php endif; ?>
  <button type="button" onClick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
</form>