Community Forums

When customer hits Add to Cart button, want to redirect them

General support for technical problems with OpenCart v1.x

When customer hits Add to Cart button, want to redirect them

Postby freni32 » Wed Nov 10, 2010 7:13 am

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

Postby Qphoria » Wed Nov 10, 2010 2:24 pm

In Extensions->Modules under "Cart" you can disable ajax
Image Image
Donate!|OpenCart Basics|GeoZones
Help me get more development cloud storage - Click Here to get DropBox
User avatar
Qphoria
Administrator
 
Posts: 18210
Joined: Mon Jul 21, 2008 7:02 pm
Donate to Qphoria

Re: When customer hits Add to Cart button, want to redirect

Postby freni32 » Wed Nov 10, 2010 5:52 pm

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

Postby oleg » Wed Jul 13, 2011 9:58 pm

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
oleg
 
Posts: 8
Joined: Wed Jul 13, 2011 8:50 pm
Location: Israel

Re: When customer hits Add to Cart button, want to redirect

Postby oleg » Thu Jul 14, 2011 1: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
oleg
 
Posts: 8
Joined: Wed Jul 13, 2011 8:50 pm
Location: Israel

Re: When customer hits Add to Cart button, want to redirect

Postby Emoney » Thu Jul 21, 2011 4:47 pm

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>
Emoney
 
Posts: 2
Joined: Thu Jul 21, 2011 12:53 pm

Re: When customer hits Add to Cart button, want to redirect

Postby T3CustomPCs » Wed Jul 27, 2011 10:36 pm

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.
T3CustomPCs
 
Posts: 9
Joined: Mon Jul 25, 2011 7:14 pm

Re: When customer hits Add to Cart button, want to redirect

Postby uksitebuilder » Wed Aug 03, 2011 8:53 am

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
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

Postby let-it-go » Mon Aug 08, 2011 2:46 pm

@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

Postby darrengould » Fri Aug 12, 2011 8:47 am

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.
darrengould
 
Posts: 55
Joined: Fri Mar 25, 2011 1:07 pm

Re: When customer hits Add to Cart button, want to redirect

Postby tunnu » Fri Aug 12, 2011 12:52 pm

I am using 1.4.9.4

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

Postby kommancero » Fri Oct 07, 2011 10:51 pm

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

Postby uksitebuilder » Sat Oct 08, 2011 7:16 am

What operation will the if statement perform ?
User avatar
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

Postby kommancero » Tue Oct 11, 2011 2: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.
kommancero
 
Posts: 5
Joined: Mon Oct 03, 2011 6:11 pm

Re: When customer hits Add to Cart button, want to redirect

Postby sferris » Fri Oct 28, 2011 5:08 pm

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

Postby sferris » Fri Oct 28, 2011 5:23 pm

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.
sferris
 
Posts: 36
Joined: Fri Jul 15, 2011 4:46 pm

Re: When customer hits Add to Cart button, want to redirect

Postby uksitebuilder » Fri Oct 28, 2011 5:31 pm

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
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

Postby Gui Siani » Tue Feb 14, 2012 11:55 pm

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

Postby jparkley » Sat Feb 18, 2012 7:11 pm

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

Postby rasahydro » Thu Feb 23, 2012 5:05 pm

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

Next

Return to General Support

Who is online

Users browsing this forum: Bing [Bot], djudez, granddaddy, ja434650, labeshops, NoJoke, rph, theviewer1985, virtualgeorge, WilliamBD and 70 guests

Hosted by Arvixe Web Hosting