1
votes

How can I add quantity option to each product item in the category list page?

By default, you can find this in Magento list.phtml,

<?php if($_product->isSaleable()): ?>
    <p><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></p>
<?php else: ?>
    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>

So every time you click the Add to Cart button, it is only 1 quantity to be added to the shopping cart.

I want to add this option so the customer can add the quantity they want at this stage,

<?php if(!$_product->isGrouped()): ?>
    <input type="text" name="qty" id="qty" placeholder="1" maxlength="12" value="<?php echo $_product->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty input-quantity" />
<?php endif; ?>

The first problem is that <?php echo $_product->getProductDefaultQty() * 1 ?> always shows the value of 0.

The second problem is that if I put the quantity value manually to be, say 20, I will still get 1 only for that product item that I have clicked to add to the shopping cart.

Any ideas?

1

1 Answers

6
votes

try this code instead of Add To Cart button

<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" class="input-text qty" name="qty" id="qty" maxlength="12" value="<?php echo ($this->getMinimalQty($_product)?$this->getMinimalQty($_product):1) ?>" />
            <?php endif; ?>
            <button type="button" class="button" onclick="this.form.submit()"><span><span><span><?php echo $this->__('Add to Cart') ?></span></span></span></button>
  </form>

Hope this will works for you.