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.

asked Sep 22, 2017 at 6:49

2 Answers 2

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>
answered Sep 22, 2017 at 8:34
6
  • But quantity not increasing Commented Sep 22, 2017 at 9:15
  • this solution will simply redirect to checkout page, without incrementing the qty Commented Sep 22, 2017 at 9:36
  • @Ramesh S yes, he gets a product without qty, you need a little update for this Commented Sep 22, 2017 at 9:45
  • @Prince: Sorry for my wrong question. How can i increase qty Commented Sep 22, 2017 at 10:18
  • @Prince: Please check my code now i can incrementing the quntity magento.stackexchange.com/questions/194261/… Commented Sep 22, 2017 at 13:23
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();

answered Sep 22, 2017 at 13:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.