Post by freni32 » Wed Nov 10, 2010 3:13 pm

Right now when a customer looks at my product on my website, and then hits the "Add To Cart" button, it stays on the same page they were on but moves that product to the left sidebar and adds the product to the cart. My site most of the customers are older and not advanced on computers and think that the button "Add To Cart" isn't working. I would like for the system instead when they hit "Add To Cart" to take them to the "View Cart" page, where they can see the total and the price, and then hit "Checkout" from there. How would I do this?

New member

Posts

Joined
Wed Sep 08, 2010 5:48 am

Post by Qphoria » Wed Nov 10, 2010 10:24 pm

In Extensions->Modules under "Cart" you can disable ajax

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by freni32 » Thu Nov 11, 2010 1:52 am

Wow that was easy!!! thank you very much!!

New member

Posts

Joined
Wed Sep 08, 2010 5:48 am

Post by oleg » Thu Jul 14, 2011 5:58 am

In opencart 1.5.0.5v, there is no way to do it from the admin panel like in earlier versions.

I have seen different php based solutions that haven't worked for me, so I've came with my own javascript based solution.

The idea is very simple. You just have to append a redirect command to onclick event.

instead of

Code: Select all

<a class="button" onclick="addToCart('73');">
use

Code: Select all

<a class="button" onclick="addToCart('73');window.location='index.php?route=checkout/cart';">
or (not tested yet) if there are no onclick event, just add one with the redirect, or just add the redirect at the end of the addToCart function

Working on hebrew rtl opencart 1.5.0.5v http://automoto.co.il


Newbie

Posts

Joined
Thu Jul 14, 2011 4:50 am
Location - Israel

Post by oleg » Thu Jul 14, 2011 9:54 pm

There is a little problem with this method. Sometimes the redirect works faster than the ajax add to cart code, it does add a product to cart, but when you get to the carts page you don't see the product until you refresh. To solve this you can use setTimeout().

add to common.js function

Code: Select all

function RedirectToCart(){
	window.location='index.php?route=checkout/cart';
}
and instead of

Code: Select all

<a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button">
use

Code: Select all

<a onclick="addToCart('<?php echo $product['product_id']; ?>');setTimeout('RedirectToCart()',2000);" class="button">

Working on hebrew rtl opencart 1.5.0.5v http://automoto.co.il


Newbie

Posts

Joined
Thu Jul 14, 2011 4:50 am
Location - Israel

Post by Emoney » Fri Jul 22, 2011 12:47 am

The problem is that, regardless of whether the AJAX module is enabled and turned on, there is still a line of code in your theme's common/header.tpl that includes an AJAX call on click.

So the simple solution is to do the window.location trick to redirect -- after the AJAX call has returned successfully, to avoid asynchronous issues and javascript timeout hacks.

Here's my modified code from my header.tpl file. I hope this helps.

<script type="text/javascript">
$(document).ready(function () {
$('#add_to_cart').removeAttr('onclick');

$('#add_to_cart').click(function () {
$.ajax({
type: 'post',
url: 'index.php?route=module/cart/minicart',
dataType: 'html',
data: $('#product :input'),
success: function (html) {
$('#header_cart .center').html(html);
window.location='index.php?route=checkout/cart'; #redirect to cart
}
});
});
});
</script>

Newbie

Posts

Joined
Thu Jul 21, 2011 8:53 pm

Post by T3CustomPCs » Thu Jul 28, 2011 6:36 am

Hi all i want to do is when customers add to cart it take them to the shopping cart page.
I am using OC 1.5.1.1 with the Shoppica theme.
Could you please tell me exactly what file i need to edit and what exactly i need to find and replace.

Newbie

Posts

Joined
Tue Jul 26, 2011 3:14 am

Post by uksitebuilder » Wed Aug 03, 2011 4:53 pm

in catalog/view/javascript/common.js

find:

Code: Select all

			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#cart_total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}	
replace with:

Code: Select all

			if (json['success']) {
				window.location='index.php?route=checkout/cart'; 
			}	

User avatar
Guru Member

Posts

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

Post by let-it-go » Mon Aug 08, 2011 10:46 pm

@uksitebuilder, thanks, works well for my site. And i also did it in the product.tpl.

Newbie

Posts

Joined
Mon Aug 08, 2011 10:42 pm

Post by darrengould » Fri Aug 12, 2011 4:47 pm

Did it work because I just tried it and couldn't get it to work for me

Using V1.5.1

Still don't know why showing the cart isn't an option as I prefer it that way and always will.

At least some people expect to see what they have ordered when they click on a button to add to cart.

If others prefer it this way fine but make it a choice thing. Just another bit of OC that appears to be faltering.

I seriously would have left OC ages ago if I hadn't spent so much on mods.

New member

Posts

Joined
Fri Mar 25, 2011 9:07 pm

Post by tunnu » Fri Aug 12, 2011 8:52 pm

I am using 1.4.9.4

its not working when i turn off ajax in Extensions>Cart

Help me now :(

New member

Posts

Joined
Sun Jun 05, 2011 11:38 pm

Post by kommancero » Sat Oct 08, 2011 6:51 am

Hi I'm using 1.5.3 and I want to put an if statement after user clicks add to cart button. I could not find where to put that if statement. can anyone help?

Newbie

Posts

Joined
Tue Oct 04, 2011 2:11 am

Post by uksitebuilder » Sat Oct 08, 2011 3:16 pm

What operation will the if statement perform ?

User avatar
Guru Member

Posts

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

Post by kommancero » Tue Oct 11, 2011 10:56 pm

I'm going to check a manufacturer's id from database. and compare it with the one's that is already in the cart. So basically I want the customers to buy from only one manufacturer.

Newbie

Posts

Joined
Tue Oct 04, 2011 2:11 am

Post by sferris » Sat Oct 29, 2011 1:08 am

uksitebuilder wrote:in catalog/view/javascript/common.js

find:

Code: Select all

			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#cart_total').html(json['total']);
				
				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}	
replace with:

Code: Select all

			if (json['success']) {
				window.location='index.php?route=checkout/cart'; 
			}	

I'm using 1.5.0.5 and this works beautifully on the home and categories page, but not the products page. Here's the weird thing - it works if I click add to cart on a product in the Related Products tab, but it doesn't work on the button right next to the product on the page (doesn't matter if there are related products or not).

Any ideas?

New member

Posts

Joined
Sat Jul 16, 2011 12:46 am

Post by sferris » Sat Oct 29, 2011 1:23 am

Answered my own question after I looked at the code a little closer. On the products.tpl, the button code is:

<a id="button-cart" class="button"><span><?php echo $button_cart; ?></span></a>

and it should be:

<a class="button" onclick="addToCart('<?php echo $product_id; ?>');"><span><?php echo $button_cart; ?></span></a>

Once I change this, it worked. Just an FYI for anyone else having issues.

New member

Posts

Joined
Sat Jul 16, 2011 12:46 am

Post by uksitebuilder » Sat Oct 29, 2011 1:31 am

Add to cart javascript for the products page is at the bottom of the product.tpl rather than in the common.js file

User avatar
Guru Member

Posts

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

Post by Gui Siani » Wed Feb 15, 2012 7:55 am

iksitebuilder, Where exactly do we have change in product.tpl?

New member

Posts

Joined
Tue Jul 12, 2011 1:48 am

Post by jparkley » Sun Feb 19, 2012 3:11 am

Thanks, sferris! I'm using 1.5.1.3 and it works for me!

Newbie

Posts

Joined
Mon Feb 06, 2012 3:58 am

Post by rasahydro » Fri Feb 24, 2012 1:05 am

I did this and found that it does not work on internet explorer but it does work on mozilla and safari

Newbie

Posts

Joined
Thu Oct 13, 2011 9:07 am
Who is online

Users browsing this forum: Bing [Bot] and 140 guests