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?
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');">
Code: Select all
<a class="button" onclick="addToCart('73');window.location='index.php?route=checkout/cart';">
Working on hebrew rtl opencart 1.5.0.5v http://automoto.co.il
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';
}
Code: Select all
<a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button">
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
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>
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.
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');
}
Code: Select all
if (json['success']) {
window.location='index.php?route=checkout/cart';
}
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.
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?
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.
uksitebuilder wrote:in catalog/view/javascript/common.js
find:replace with: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'); }
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?
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.
Add to cart javascript for the products page is at the bottom of the product.tpl rather than in the common.js file
Who is online
Users browsing this forum: Bing [Bot] and 140 guests