4
votes

I'm developing a magento store and in the product view page/details page i have added a jquery quantity box.It works fine.But when click on the add to cart button always add "1" to the cart although i changed the quantity amount in the quantity box.I searched this issue in every place possible sites.But still no luck.And i have placed the input quantity box at the correct place.That means inside the form.I can't figure it out the issue.Hope a help.And my Magento version is 1.8.

2
Finally could solved the issue by my own.I mark this question as solved.CodeCanyon
Please post your answer and accept it. So that everyone can resolve the problem if they has.Nandakumar

2 Answers

1
votes

This works with form tag... you can edit your default/theme/template/catalog/product/view/addtocart.phtml like this.

<form>
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <label class="qty_label" for="qty"><?php echo $this->__('Quantity') ?>:</label>
<div class="qty_pan">
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
<?php endif; ?>
</form>
1
votes

From Magento version 1.8 onwards, you need to add formkey value inside your form.

If formkey is not set in the form, then always the default qty 1 will be added to cart.

Also, if you try to update the qty from cart page, it will not get updated and will always be set to 1.

To solve this issue, add the following code inside the <form > tag:

<?php echo $this->getBlockHtml('formkey'); ?>

This code is similar to:

<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />

Porduct View Page

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/catalog/product/view.phtml

<form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form">
    <?php echo $this->getBlockHtml('formkey'); ?>

Shopping Cart Page

app/design/frontend/YOUR_PACKAGE/YOUR_THEME/checkout/cart.phtml

<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
    <?php echo $this->getBlockHtml('formkey'); ?>