1

I am using Magento 1.8. and custom theme. I have added the button called BUY NOW for each product, and url of that button is
echo Mage::helper('checkout/url')->getCheckoutUrl($_product); It redirects to checkout but Its unable to add that product to cart.

How it is possible to add product to cart and redirect to checkout page by on click of BUY NOW button.

Thanks.

1

To add product in the cart and from there you can proceed to checkout.

Try

Mage::helper('checkout/cart')->getAddUrl($_product);

This will generate add to cart link

0

If I understand correctly, you've essentially renamed the "Add to cart" button to "Buy now" and would like to by-pass the cart and go directly to the checkout page.

To achieve this do the following:

  1. Copy CartController.php from /app/code/core/Mage/Checkout/controllers/ to /app/code/local/Mage/Checkout/controllers

  2. At line 95 of CartController.php replace

    $this->_redirect('checkout/cart');

With

 $this->_redirect('checkout/onepage'); 

To disable this functionality, delete the file from the local sub-directory.

0

Magento generates an add to cart url for add to cart buttons.

It's in the form of

http://{YOUR SITE NAME}/checkout/cart/add/uenc/{Base64 Encoded Redirect Url},/product/{PRODUCT ID}/form_key/{FORM KEY}/

$url = strtr(base64_encode($url), '+/=', '-_,'); // for base64 encode

$form_key = Mage::getSingleton('core/session')->getFormKey(); // for getting form_key

if you use http://{YOUR SITE NAME}/checkout/onepage as redirect url magento redirect you directly to checkout after product added to cart.

You only have to make a button which redirects to this url. // onclick=setLocation(url);

0

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

FInd the line $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);
}

Code Taken from this link http://chandreshrana.blogspot.in/2016/01/how-to-add-buynow-button-on-product.html

  • Are you sure controllers can be re-written this way ? – Prateek Jan 11 '16 at 14:52
  • You can override the cart controller from your own module with the help of config.xml – Chandresh Rana Jan 12 '16 at 5:27
  • Then please mention that too in your answer. It is a little misleading right now. – Prateek Jan 12 '16 at 5:42

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.