Unwanted form_key popup
-
01-10-2020 - |
Pergunta
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>
Solução
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.