0

IF we click on "Buy now " button in view page

its redirecting to cart page. we are using following code :

<button class="button buy-now" onclick=”location.href =’{{config path=”web/unsecure/base_url”}}/checkout/cart/add?product=1&qty=1′”>
<span><span><i class="fa fa-shopping-cart"></i>Buy Now</span></span></button>

we are using following code for "Add to cart" button, what we need is if we click on "add to cart" button,

than it should redirect to cart page.

<button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" 
onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>

edit

JS code :

 productAddToCartForm.submit = function(button, url) {
            if (('undefined' != typeof productAddToCartFormOld) && productAddToCartFormOld) {
                if (Catalog.Map.active) {
                    Catalog.Map.hideHelp();
                }
                if (productAddToCartForm.qty && $('qty')) {
                    $('qty').value = productAddToCartForm.qty;
                }
                parentResult = productAddToCartFormOld.submit();
                return false;
            }
            if(window.opener) {
                var parentButton = button;
                new Ajax.Request(this.form.action, {
                    parameters: {isAjax: 1, method: 'GET'},
                    onSuccess: function(transport) {
                        window.opener.focus();
                        if (parentButton && parentButton.href) {
                            setPLocation(parentButton.href, true);
                            Catalog.Map.hideHelp();
                        }
                    }
                });
                return;
            }
            if (this.validator.validate()) {
                var form = this.form;
                var oldUrl = form.action;

                if (url) {
                   form.action = url;
                }
                if (!form.getAttribute('action')) {
                   form.action = productAddToCartForm.action;
                }
                try {
                    this.form.submit();
                } catch (e) {
                    this.form.action = oldUrl;
                    throw e;
                }
                this.form.action = oldUrl;

                if (button && button != 'undefined') {
                    button.disabled = true;
                }
            }
        };
19
  • On "Buy Now" button what action you needed? Commented Mar 4, 2016 at 10:16
  • Buty now is fine, if i click on "Add to cart", it should redirect to cart page Commented Mar 4, 2016 at 10:17
  • I remember this can be achieved by admin. Did you try with Sales -> Checkout -> After Adding a Product Redirect to Shopping Cart ?
    – Prateek
    Commented Mar 4, 2016 at 10:17
  • actually we are using 2 add to cart buttons, one button for add to cart and another one for Buy now. I will use add to cart functionailty and put the text "Buy Now" Commented Mar 4, 2016 at 10:19
  • You can try this answer of mine : magento.stackexchange.com/questions/97912/…
    – Prateek
    Commented Mar 4, 2016 at 10:22

1 Answer 1

1

Change your js code with default magento code as below

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);
12
  • sorry still its not working : link Commented Mar 4, 2016 at 13:17
  • Disable extension Em_Ajaxcart and try again Commented Mar 4, 2016 at 13:42
  • still not working Commented Mar 4, 2016 at 13:50
  • Its working for me i have just checked on your store Commented Mar 4, 2016 at 13:53
  • pls check with above link Commented Mar 4, 2016 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.