I want to show two Add To Cart button in view.phtml page. those buttons are following,
- Add To Cart
- 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/onepagepage. How can i do this.
2 Answers 2
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>
-
But quantity not increasingRamesh S– Ramesh S2017年09月22日 09:15:52 +00:00Commented Sep 22, 2017 at 9:15
-
this solution will simply redirect to checkout page, without incrementing the qtyManashvi Birla– Manashvi Birla2017年09月22日 09:36:34 +00:00Commented Sep 22, 2017 at 9:36
-
@Ramesh S yes, he gets a product without qty, you need a little update for this2017年09月22日 09:45:05 +00:00Commented Sep 22, 2017 at 9:45
-
@Prince: Sorry for my wrong question. How can i increase qtyRamesh S– Ramesh S2017年09月22日 10:18:42 +00:00Commented Sep 22, 2017 at 10:18
-
@Prince: Please check my code now i can incrementing the quntity magento.stackexchange.com/questions/194261/…Ramesh S– Ramesh S2017年09月22日 13:23:44 +00:00Commented Sep 22, 2017 at 13:23
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();