0

So I just added a Buy Now button in my store using this previously answered question: Magento 1.9 How to add buy now button in product page?

Everything works fine, however I'm getting a pop up after pressing the Buy Now button.

It reads:

www.mystore.net says: https://www.mystore.net/checkout/cart/add/uenc/aHR0cHM6Ly93d3cucGI4ZWxtYXJrZXQubmV0L3dhbmQuaHRtbA,,/product/8/form_key/qPvLAuhxmDQklkqt/

Image: http://i.imgur.com/qWTgiGU.png

Is there anyway to just bypass it throwing this message?

Javascript added to app/design/frontend/ultimo/pixel/template/catalog/product/view.pthml:

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

    /* add return Url */
    var inputreturn= document.createElement("input");
    inputreturn.type = "hidden";
    inputreturn.name = "return_url";
    inputreturn.value = "<?php echo Mage::getUrl('checkout/onepage')?>";
        document.getElementById('product_addtocart_form').appendChild(inputreturn);
    /* add return Url */
    // Append a line break 
    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(productBuyNowForm); 

Button added to app/design/frontend/ultimo/pixel/template/catalog/product/view/addtocart.phtml:

<button type="button" 
    title="<?php echo $buttonTitle ?>"
    class="button btn-cart" 
    onclick="productBuyNowForm.submit(this)">
 <span><span>Buynow</span></span>
</button>
1

Remove this line:

alert(form.action);

It was probably added for debugging and then forgotten to remove.

Tip: Use console.log for debug output to print to the browser console instead of alert

Pro Tip: Every major browser comes with a JavaScript debugger where you can set breakpoints and inspect variables. This is even better than adding debug output to your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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