Jump to content

[Solved] A Buy Now button along with Add to Cart


Vee.K727

Recommended Posts

I have an ajax add to cart button on my product page but would like to create another one for Buy Now. It'll be same as Add to Cart but after adding the product to the cart, user will be redirected to the cart page.

 

This question has been discussed before but not recently and their solutions didn't work on the latest prestashop installations (I have 1.6.1).

 

Can anyone help me with that? Or explain how this button functions?

Edited by Vee.K727 (see edit history)
Link to comment
Share on other sites

Hi,

if you are still interested, you can add this button near your Add to cart button, and this will work out as you wanted.

Please add this code to your product.tpl inside the Add to cart Form and test it out.

 

{if isset($static_token)}
<a class="button buy_now_button btn btn-default" href="{$link->getPageLink('cart',false, NULL, "add=1&id_product={$product->id|intval}&token={$static_token}", false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Buy Now'}" data-id-product="{$product->id|intval}"  onclick="this.href = this.href+ '&qty='+$('.buy_now_button').closest('form').find('#quantity_wanted').val() + '&ipa='+  $('.buy_now_button').closest('form').find('#idCombination').val(); " >
<span>{l s='Buy Now1'}</span>
</a>
{else}
<a class="button buy_now_button btn btn-default" href="{$link->getPageLink('cart',false, NULL, 'add=1&id_product={$product->id|intval}', false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Buy Now'}" data-id-product="{$product->id|intval}" onclick="this.href = this.href+ '&qty='+$('.buy_now_button').closest('form').find('#quantity_wanted').val() + '&ipa='+  $('.buy_now_button').closest('form').find('#idCombination').val(); " >
<span>{l s='Buy Now'}</span>
</a>
{/if}
 
Kind regards, Leo
Link to comment
Share on other sites

Thanks Leo for the code. I am still interested in it.

 

Your first code does work (the one in the "if" part) but the second one (in the "else" part) doesn't. The problem is somewhere in the "onclick" part. The page does break down and says "Localhost is unable to handle the request. Would you know why that may be?

 

is the "if" statement important? Can I use the first version at all times?

Link to comment
Share on other sites

  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...