2

I'm new to Magento. I want to add the buy now button along with the Add to cart button on the product page. I have searched for that, I found this solution :

<button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/onepage') ?>')"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>

<script>
    function setcheckoutLocation(location,chkout)
    {
        jQuery.ajax({
            type:"GET",
            url:location,
            success:function(data){
                 window.location.href = chkout;
            }
        });
    }
</script>

But it add the product to cart and then redirects to onepage and in the checkout process, all the products that are in the cart are added.

Is There any way that the product which we have selected for buy now will only be added to the checkout process regardless of products in the cart. Thanks in advance.

3
  • By default NO.. – Minesh Patel Apr 2 '16 at 11:54
  • @MineshPatel do you know any extension which will do the task or another way Thanks – Shrikant Apr 2 '16 at 12:38
  • well not sure about extension but if you really want it you need to create module for that and it will break magento's checkout flow as magento does not allow checkout for single item from cart – Minesh Patel Apr 4 '16 at 4:39
1

Hello @Srikant you have to create a form on the product page and the action should be checkout link :

<?php 
   $product = Mage::getModel ( 'catalog/product' )->load ( $product_id );
   $url = Mage::helper ( 'checkout/cart' )->getAddUrl ( $product, array ('qty' => 1 ) );
?>

In url $product is product object

<form method="post" name="form-name"action="<?php echo $url;?>">
       <button type="submit" class="btn_goto"><?php echo $this->__('Buy Now') ?>   
</form>

Now clicking on the buy now you will be redirected to the checkout page directly. The form should be individual for each product.

2
  • Thanks for the reply., but when I'm clicking on the buy now button it is redirecting to the cart page because url is created in that way, however I want it should be redirected to checkout/onepage. How to do this? – Shrikant Apr 4 '16 at 6:38
  • According to me you have to use module to reduce checkout step try following : magentocommerce.com/magento-connect/reduced-checkout-free.html – Manish Apr 4 '16 at 6:59
0

Try this solution.

In your app\design\frontend\default[yourtheme]\template\catalog\product\view\addtocart.phtml add the below code after add to cart button.

<button type="button" title="<?php echo $this->__('Check out') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/url') ?>')"><span><span><?php echo $this->__('Buy Now') ?></span></span></button>
 <script>
 function setcheckoutLocation(location,chkout)
 {
  jQuery.ajax({
                type:"GET",
                url:location,
                success:function(data){
                     window.location.href = chkout;
                }
             });
}
</script>
1
  • I am already trying this snippet as in my quesiton. But when there are items already in cart, this leads to checkout of 2 items including one from before and one from buy now. how can we only checkout buy now item – Shrikant Apr 2 '16 at 11:35

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.