Monday, 11 January 2016

How to add buynow button on product page in magento


How to add buynow button on product page in magento

Kindly open app/design/frontend/package/theme/template/catalog/product/view.phtml

Add below line into <form> Tag

<input type="hidden" name="buy_now" id="buy_now" value="" />

Put below button at anywhere where you want

<button type="button" onclick="jQuery('#buy_now').val('buy_now');productAddToCartForm.submit(this)" class="btn btn-block btn-express-buynow"><i class="cart-icon-white m-r-sm v-middle"></i>Buy Now</button>

Now open app/code/core/Mage/Checkout/controllers/CartController.php

Change the code as below instructions

Put below line in _goBack() function at very first

$buy_now = $this->getRequest()->getParam('buy_now');

FInd the line in _goBack() function $this->getResponse()->setRedirect($backUrl); and replace this line as below code

    if (!empty($buy_now)) {
        $this->_redirect('onepagecheckout'); // If you are using onepagecheckout or use this $this->_redirect('checkout/onepage/')
    }else{
        $this->getResponse()->setRedirect($backUrl);
    }

That's it. Enjoy Chandresh rana's Coding...

8 comments:

philip said...

I just want to know if this approach has validation if a product has custom options or configurable?

PHP Coder said...

Yes validation works with both options

philip said...

I tried your code but it's behaving like ADD TO Cart button. It's not redirecting to checkout page when I click Buy Now. It should skip the shopping cart.

PHP Coder said...

Go to system->configuration->Sales->checkout and set "No" of After Adding a Product Redirect to Shopping Cart

philip said...

Hi. My settings is already set like that.

jpnuclear said...

Hi, how I can change css style to this new Buy button?, "class:btn btn-block btn-express-buynow" but where i can configure or edit this style? Tanks (:

PHP Coder said...

You can change this class and put your own class then write the css according to you.

YOGESH LAVANIA said...

I created a block inside app/design/frontend/ultimo/default/template/catalog/product/view/firesale.phtml, I wand to ass Buy now button. It is possible if yes then how.