When customer hits Add to Cart button, want to redirect them
29 posts
• Page 1 of 2 • 1, 2
When customer hits Add to Cart button, want to redirect them
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?
- freni32
- Posts: 67
- Joined: Tue Sep 07, 2010 9:48 pm
Re: When customer hits Add to Cart button, want to redirect
In Extensions->Modules under "Cart" you can disable ajax

Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
-

Qphoria - Administrator
- Posts: 18210
- Joined: Mon Jul 21, 2008 7:02 pm

Re: When customer hits Add to Cart button, want to redirect
Wow that was easy!!! thank you very much!!
- freni32
- Posts: 67
- Joined: Tue Sep 07, 2010 9:48 pm
Re: When customer hits Add to Cart button, want to redirect
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
use
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
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
- oleg
- Posts: 8
- Joined: Wed Jul 13, 2011 8:50 pm
- Location: Israel
Re: When customer hits Add to Cart button, want to redirect
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
and instead of
use
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
- oleg
- Posts: 8
- Joined: Wed Jul 13, 2011 8:50 pm
- Location: Israel
Re: When customer hits Add to Cart button, want to redirect
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>
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>
- Emoney
- Posts: 2
- Joined: Thu Jul 21, 2011 12:53 pm
Re: When customer hits Add to Cart button, want to redirect
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.
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.
- T3CustomPCs
- Posts: 9
- Joined: Mon Jul 25, 2011 7:14 pm
Re: When customer hits Add to Cart button, want to redirect
in catalog/view/javascript/common.js
find:
replace with:
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';
}
Happy Coding!
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
-

uksitebuilder - Posts: 5602
- Joined: Thu Jun 09, 2011 3:37 pm
- Location: United Kindgom
Re: When customer hits Add to Cart button, want to redirect
@uksitebuilder, thanks, works well for my site. And i also did it in the product.tpl.
- let-it-go
- Posts: 2
- Joined: Mon Aug 08, 2011 2:42 pm
Re: When customer hits Add to Cart button, want to redirect
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.
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.
- darrengould
- Posts: 55
- Joined: Fri Mar 25, 2011 1:07 pm
Re: When customer hits Add to Cart button, want to redirect
I am using 1.4.9.4
its not working when i turn off ajax in Extensions>Cart
Help me now
its not working when i turn off ajax in Extensions>Cart
Help me now

- tunnu
- Posts: 31
- Joined: Sun Jun 05, 2011 3:38 pm
Re: When customer hits Add to Cart button, want to redirect
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?
- kommancero
- Posts: 5
- Joined: Mon Oct 03, 2011 6:11 pm
Re: When customer hits Add to Cart button, want to redirect
What operation will the if statement perform ?
Happy Coding!
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
-

uksitebuilder - Posts: 5602
- Joined: Thu Jun 09, 2011 3:37 pm
- Location: United Kindgom
Re: When customer hits Add to Cart button, want to redirect
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.
- kommancero
- Posts: 5
- Joined: Mon Oct 03, 2011 6:11 pm
Re: When customer hits Add to Cart button, want to redirect
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?
- sferris
- Posts: 36
- Joined: Fri Jul 15, 2011 4:46 pm
Re: When customer hits Add to Cart button, want to redirect
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.
<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.
- sferris
- Posts: 36
- Joined: Fri Jul 15, 2011 4:46 pm
Re: When customer hits Add to Cart button, want to redirect
Add to cart javascript for the products page is at the bottom of the product.tpl rather than in the common.js file
Happy Coding!
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
-

uksitebuilder - Posts: 5602
- Joined: Thu Jun 09, 2011 3:37 pm
- Location: United Kindgom
Re: When customer hits Add to Cart button, want to redirect
iksitebuilder, Where exactly do we have change in product.tpl?
- Gui Siani
- Posts: 23
- Joined: Mon Jul 11, 2011 5:48 pm
Re: When customer hits Add to Cart button, want to redirect
Thanks, sferris! I'm using 1.5.1.3 and it works for me!
- jparkley
- Posts: 1
- Joined: Sun Feb 05, 2012 7:58 pm
Re: When customer hits Add to Cart button, want to redirect
I did this and found that it does not work on internet explorer but it does work on mozilla and safari
- rasahydro
- Posts: 16
- Joined: Thu Oct 13, 2011 1:07 am
29 posts
• Page 1 of 2 • 1, 2
Who is online
Users browsing this forum: Bing [Bot], djudez, granddaddy, ja434650, labeshops, NoJoke, rph, theviewer1985, virtualgeorge, WilliamBD and 70 guests













