user3302074
user3302074

Reputation:

Magento: Add to Cart adds alway double quantity, why?

Call add to cart: <button title="<?php echo $buttonTitle ?>" class="btn" onclick="productAddToCartForm.submit();"><span><span><?php echo $buttonTitle ?></span></span></button>

JS Code that send the product to cart, but with double qty. It should qty 1 but in cart is qty 2.

 var productAddToCartForm = new VarienForm('product_addtocart_form');
    productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }
    }.bind(productAddToCartForm);

When I navigate to the add to cart form submit link directly, the qty is also double in the cart. http://example.com/checkout/cart/add?product=55&qty=1 (adds double qty)

Upvotes: 0

Views: 1569

Answers (2)

MageCoder
MageCoder

Reputation: 111

Go to app/design/frontend/{theme}/default/template/catalog/product/view/addtocart.phtml

Find ADD to Cart button and replace the code on on click event

onclick="productAddToCartForm.submit(); return false;"

Upvotes: 1

Balaji Kandasamy
Balaji Kandasamy

Reputation: 4506

Try to change

onclick="productAddToCartForm.submit();"

with:

onclick="productAddToCartForm.submit(); return false;"

or

onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"

Refer this link for more details: http://importantmagento.blogspot.in/2012/07/magento-fix-add-to-cart-button-adds.html

Upvotes: 2

Related Questions