Post by colt1911 » Fri Nov 18, 2011 1:23 am

Hi guys, I searched for this but could not find. I did find an old thread from 2009 - http://forum.opencart.com/viewtopic.php?t=6756 - but I think the older version (1.4) makes this not work with my version 1.5.1.1. When I added it, the link did not show up, plus everything below it disappeared.

Can anyone tell me how to add a checkout link next to the "Add to Cart" button on product.tpl?

Thanks! ;D
Last edited by colt1911 on Mon Dec 05, 2011 7:17 pm, edited 1 time in total.

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by uksitebuilder » Fri Nov 18, 2011 3:43 am

edit: catalog/view/theme/default/template/product/product.tpl

find

Code: Select all

&nbsp;<a id="button-cart"
add before

Code: Select all

&nbsp;<a id="button-checkout" class="button"><span><?php echo $button_checkout; ?></span></a>
find

Code: Select all

<script type="text/javascript"><!--
$('#button-cart').bind('click', function() {
add before

Code: Select all

<script type="text/javascript"><!--
$('#button-checkout').bind('click', function() {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, information, .error').remove();
			
			if (json['error']) {
				if (json['error']['warning']) {
					$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
					$('.warning').fadeIn('slow');
				}
				
				for (i in json['error']) {
					$('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>');
				}
			}	 
						
			if (json['success']) {
				location = 'index.php?route=checkout/checkout'; 
			}	
		}
	});
});
//--></script>
edit: catalog/controller/product/product.php

find

Code: Select all

			$this->data['button_cart'] = $this->language->get('button_cart');
add before

Code: Select all

			$this->data['button_checkout'] = $this->language->get('button_checkout');
edit: catalog/language/yourlanguage/product/product.php

add a new define

Code: Select all

$_['button_checkout']       = 'Checkout';

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by colt1911 » Tue Nov 29, 2011 6:31 am

Hi Simon,

Please excuse the late response -- the Thanksgiving holiday wiped me out.

Thank you so much for helping me with this.

Unfortunately I'm getting an error on the product page:

Notice: Undefined variable: button_checkout in /home/testsite/catalog/view/theme/custom-test/template/product/product_giftcard.tpl on line 190

I changed

Code: Select all

<?php echo $button_checkout; ?>
to

Code: Select all

Checkout
and the error went away, but then when you clicked on the button nothing happened.

Any idea what I'm doing wrong? :-\

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by colt1911 » Tue Nov 29, 2011 6:40 am

Simon...

This code also gives me a syntax error in my editor, if that makes any difference:

Code: Select all

location = index.php?route=checkout/checkout;

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by uksitebuilder » Sat Dec 03, 2011 6:16 pm

Apolgies - I have fixed my code above

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by colt1911 » Mon Dec 05, 2011 6:58 am

Thank you, uksitebuilder. Right before I got your code, a friend of mine started to work on this issue. He came up with this solution:

Code: Select all

<a id="go-checkout" class="button" onclick="window.location='http://localhost/index.php?route=checkout/checkout';"><span><?php echo 'Checkout'; ?></span></a>
Do you know whether there is anything wrong with using this? It works fine.

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by uksitebuilder » Mon Dec 05, 2011 6:34 pm

OK, I think I misunderstood your initial question

My code will add a checkout button that when clicked will add the product to the cart and then go straight to checkout with that product.

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by colt1911 » Mon Dec 05, 2011 7:16 pm

Well, no wonder that was so much more complex. Sorry about the misunderstanding. This may come in handy down the road though...thank you.

New member

Posts

Joined
Sat Sep 24, 2011 1:23 am

Post by SupraTwinTurbo » Fri Dec 09, 2011 5:08 pm

uksitebuilder wrote: edit: catalog/language/yourlanguage/product/product.php

add a new define

Code: Select all

$_['button_checkout']       = 'Checkout';
Hi Simon,

Thanks for the code to do this - I was looking for something exactly like this. Did you mean

catalog/language/english/english.php

for the

Code: Select all

$_['button_checkout']       = 'Checkout';
that is where button_cart is defined.

User avatar
New member

Posts

Joined
Thu Mar 24, 2011 12:43 pm
Location - NYC, NY USA

Post by uksitebuilder » Sat Dec 10, 2011 3:52 am

either will work - I put it in product/product though because it was specific for the product page

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by sunsys » Fri May 22, 2015 9:48 pm

uksitebuilder wrote:My code will add a checkout button that when clicked will add the product to the cart and then go straight to checkout with that product.
@UKSB: This is really fantastic script and very very useful too, I request you to please make a "CHECKOUT BUTTON" vqmod ext of this same script(add the product and then go to checkout page directly), please consider my request UKSB, you have given us such good mods, incl one more in your range.

Thank You.

PS: This will be in an extra button, ie "Add to Cart" should still be there.

Regards,
Sun Systems
Industrial Electronics and Instrumentation


User avatar
Active Member

Posts

Joined
Tue Jan 27, 2015 5:19 am
Who is online

Users browsing this forum: No registered users and 10 guests