If you want both Add to Cart and Buy now, add the buy now button to addtoCart.phtml
Go to
/app/design/frontend/[package name]/[themename]/template/ajaxcart/catalog/product/view/addtoCart.phtml
/app/design/frontend/[package name]/[themename]/template/ajaxcart/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>
On that buttons onlick event, a custom VarienForm is used, productBuyNowForm.submit(this), which will submit this form and redirect to checkout onepage.
To define this custom form, add the following JavaScript code at view.phtml
Go to
/app/design/frontend/[package name]/[theme name]/template/catalog/product/view.phtml
/app/design/frontend/[package name]/[theme name]/template/catalog/product/view.phtml
<script>
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);
</script>
No comments:
Post a Comment