Post by n0ts0smart » Fri Sep 16, 2011 10:47 am

Hi folks,

I'm not entirely sure this is in the right section, so correct me if I'm wrong. I want to know if there is any way to make the site redirect to the shopping cart after an item has been added? So instead of it just appearing in the cart either at the top or in the sidebar, you get to the screen where you're viewing your cart.

Any help would be much appreciated. Thanks!

New member

Posts

Joined
Sat Aug 28, 2010 4:59 am

Post by uksitebuilder » Fri Sep 16, 2011 11:04 pm

Try the following:

open: catalog/view/javascript/common.js

find

Code: Select all

function addToCart(product_id) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information, .error').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			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>');
				}
			}	 
						
			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'); 
			}	
		}
	});
}
change to

Code: Select all

function addToCart(product_id) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information, .error').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			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>');
				}
			}	 
						
			if (json['success']) {
				location = 'index.php?route=checkout/cart';
			}	
		}
	});
}
Works in ALL 1.5.x OC versions
You may need clear your cache

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by saintlade » Thu Dec 08, 2011 8:48 pm

Hi Guys,

have just implemented this and got it working fine but when there is a product option and you hit add to cart it just stays on the same page and doesn't add anything to the cart. Any ideas on a fix or where to look?

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by uksitebuilder » Thu Dec 08, 2011 9:28 pm

You may also need to look at the foot of the product.tpl file in catalog/view/theme/default/temlate/product/ folder

The product page uses it's own addtocart function similar to the one posted above

ImageImageImageImageImage

For Friendly Professional Support - Click Here


User avatar
Guru Member

Posts

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

Post by saintlade » Thu Dec 08, 2011 9:31 pm

Thanks, will check it out now and report back.

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by saintlade » Thu Dec 08, 2011 9:45 pm

Thanks for the help, solved this with a vQmod, only need the shopping cart add to cart button to direct straight to the shopping cart area as all my products will have options (dates of courses) so customers need to navigate to the product page in any case and I'll be removing the add to cart button in the categories area.

Here is the vQmod;

<modification>

<id>Product Add to cart direct to shopping cart</id>
<version>1.5.1.x_1</version>
<vqmver>1.0.1</vqmver>
<author>Stuart Lade</author>

<file name="/catalog/view/theme/default/template/product/product.tpl">
<operation error="skip">

<search position="replace" offset="7"><![CDATA[

$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img

src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

]]></search>

<add trim="true"><![CDATA[

location = 'index.php?route=checkout/cart';
}

]]></add>

</operation>
</file>
</modification>

New member

Posts

Joined
Wed Oct 12, 2011 9:12 am

Post by rasahydro » Thu Feb 23, 2012 10:39 am

None of the above solutions will work for internet explorer.

Newbie

Posts

Joined
Thu Oct 13, 2011 9:07 am

Post by lokust » Fri Mar 09, 2012 4:51 am

I'm using the Shoppica theme that doesn't seem to use common.js. Shoppica has a shoppica.js file with the following function:

Code: Select all

function addToCart(product_id) {
    $.ajax({
        url: 'index.php?route=module/shoppica/cartCallback',
        type: 'post',
        data: 'product_id=' + product_id,
        dataType: 'json',
        success: function(json) {

            if (json['redirect']) {
                location = json['redirect'];
            }

            if (json['error']) {
                if (json['error']['warning']) {
                    addProductNotice(json['title'], json['thumb'], json['error']['warning'], 'failure');
                }
            }

            if (json['success']) {
                addProductNotice(json['title'], json['thumb'], json['success'], 'success');
                $('#cart_menu span.s_grand_total').html(json['total_sum']);
                $('#cart_menu div.s_cart_holder').html(json['output']);
            }
        }
    });
}
Can someone help me amend this so when a user clicks Add to cart > they go straight to cart?

Thanks.

Newbie

Posts

Joined
Fri Jun 24, 2011 9:26 pm
Who is online

Users browsing this forum: Google [Bot] and 23 guests