2

I Need Add a Buy Now Button For Direct Checkout.

I Have Coded But Not Working For Configurable Products.

If There Are Any Extension For That Please Suggest Me.

4
  • Can u please share code?
    – Amit Bera
    Aug 3, 2016 at 5:16
  • Why you roll back commit
    – Amit Bera
    Aug 3, 2016 at 5:27
  • i dont think it should be edit. Aug 3, 2016 at 5:31
  • we are editing the question for improve the standard of question for all community member, by add tags & content edit. For your case,i thought , we need to improve content formating
    – Amit Bera
    Aug 3, 2016 at 5:42

1 Answer 1

3

There are two way to Can do it

1.Use existing Add to Cart

First, change Add to Cart Button to Buy Now.

Then add a hidden input field to the #product_addtocart_form form. Name should be return_url and its value should be <?php echo Mage::getUrl('checkout/onepage')?>":

<input type="hidden" value="<?php echo Mage::getUrl('checkout/onepage')?>" name="return_url" />

2.add a button Buy now with exits add to cart button

If you want both Add to Cart and Buy now, add the buy now button to 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

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);

Also ,need to add below code after productAddToCartForm.submit = function(button, url) { at view.phtml

if(!document.getElementsByName("return_url")){
    var element = document.getElementById("product_addtocart_form");
    var child=document.getElementById("return_url");
    element.removeChild(child);`
} 

this code is remove field return_url input field whenever ,you have cart from addtoCart button

9
  • Thank Amit Working fine. but issue with me is i am using Ajax Add to Cart Extension that's why not redirecting at checkout url after click buy now button. Aug 3, 2016 at 6:07
  • Just Cart is Updating but url not going at checkout Aug 3, 2016 at 6:22
  • you have using ajax cart.. this is not default magento feature, so please ask new question with ajax extension resource
    – Amit Bera
    Aug 3, 2016 at 6:26
  • i need Ajax for "Add to Cart" button and after click "Buy Now" button go at checkout Aug 3, 2016 at 6:26
  • Got Success !!! Working now Aug 3, 2016 at 7:32

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.