4

I want to show two Add To Cart button in view.phtml page. those buttons are following,

  1. Add To Cart
  2. Insta Buy

Add To Cart button working with normal functionality, It works fine.

But When user click Insta Buy directly redirect to checkout/onepage. I tried some code but it goes to checkout/cart page. That code is following

<button type="button" title="<?php echo $this->__('Insta Buy') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Insta Buy') ?></span></span></button>

I want to redirect to checkout/onepage page. How can i do this.

1

Add the code bellow in: app/design/frontend/{yourpackage}/{yourtheme}/template/catalog/product/view/addtocart.phtml

<button type="button" title="<?php echo $this->__('Insta Buy') ?>" class="button btn-cart" onclick="setcheckoutLocation('<?php echo $this->getAddToCartUrl($_product) ?>','<?php echo Mage::getUrl('checkout/onepage') ?>')"><span><span><?php echo $this->__('Insta Buy') ?></span></span></button>
 <script type="text/javascript">
     function setcheckoutLocation(location,checkout)
     {
         jQuery.ajax({
                type:"GET",
                url:location,
                success:function(data){
                     window.location.href = checkout;
                }
          });
     }
 </script>
  • Oh Prince thanks for your code it working – Ramesh S Sep 22 '17 at 9:14
  • But quantity not increasing – Ramesh S Sep 22 '17 at 9:15
  • this solution will simply redirect to checkout page, without incrementing the qty – Manashvi Birla Sep 22 '17 at 9:36
  • @Ramesh S yes, he gets a product without qty, you need a little update for this – PЯINCƏ Sep 22 '17 at 9:45
  • @Prince: Sorry for my wrong question. How can i increase qty – Ramesh S Sep 22 '17 at 10:18
2

This code for pass product data with quantity

app/design/frontend/{yourpackage}/{yourtheme}/template/catalog/product/view.phtml

Form values pass here

<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post"  id="product_addtocart_form"<?php if ($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>

. app/design/frontend/{yourpackage}/{yourtheme}/template/catalog/product/view/addtocart.phtm

Code

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

script

<script type="text/javascript">
                 function setcheckoutLocation(location,checkout)
                 {
                    var data = jQuery('#product_addtocart_form').serialize();
                    jQuery('#preloader .loader').fadeIn(300);
                     jQuery.ajax({
                            type:"post",
                            url:location,
                            data: data,
                            success:function(data){
                                 window.location.href = checkout;
                            }
                      });
                 }
             </script>

Here store all the data in var data = jQuery('#product_addtocart_form').serialize();

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.