Post by ThePath » Fri Nov 20, 2009 11:43 pm

Hi guys,

OK I am displaying the current subtotal of the cart/basket in the header by using the following code:

<?php echo $this->currency->format($this->cart->getTotal()); ?>

It displays fine but requires the user to move pages (i.e. refresh). So the question is how do I get the subtotal in the header to auto refresh like the cart module?

Any help muchly appreciated! O0
Last edited by i2Paq on Fri Oct 29, 2010 4:59 am, edited 1 time in total.
Reason: Topic moved

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by imaginetech » Fri Nov 20, 2009 11:45 pm

You'll probably need to dissect the Ajax call in cart.tpl.

Image
www.opencartstore.com
Get OpenCart Templates and OpenCart Modules.


User avatar
Active Member

Posts

Joined
Fri Sep 04, 2009 12:25 pm
Location - Darwin, Australia

Post by ThePath » Sat Nov 21, 2009 12:05 am

Yeh I wouldnt have a clue about that....Ive done a crappy fix where I have put this at the end of the afore mentioned function:

javascript:location.reload(true)

Its pants though because the whol page has to refresh. Waaaaa ???

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by Qphoria » Sat Nov 21, 2009 12:11 am

ThePath wrote:Its pants though because the whol page has to refresh. Waaaaa ???
more like underpants :)

There should be an easy way to do it with ajax....

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by ThePath » Sat Nov 21, 2009 12:55 am

Yeh but Im cack handed fool with that stuff. ???

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by ThePath » Sat Nov 21, 2009 3:18 am

I take it nobody has ever done this with OC (that we know about)?

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by dbstr » Sat Nov 21, 2009 3:31 am

Edit: Ok, seems like I misunderstood/didnt read your post carefully enough.. Just ignore this post ;-)

I have (not on a standard template tho). It's quite easy. In the module/cart.tpl you'll see:

Code: Select all

$('#module_cart .middle').html(html); 
'.middle' is most likely your problem. it's the class of your "cart content"

from a standard template:

Code: Select all

<div id="module_cart" class="box"> 
<div class="middle">   
cart content
</div>
</div>
if it was:

Code: Select all

<div id="module_cart" class="box"> 
<div class="cartcontentslalal">   
cart content
</div>
</div>
the ajax code should be

Code: Select all

$('#module_cart .cartcontentslalal').html(html); 
post a link if you can't get it to work and i'll have a look later

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by ThePath » Sat Nov 21, 2009 6:19 pm

I think your on the right track dbstr! I might try something like this a bit later on today...see what happens! Mena while any other suggestions would be mucho appreciated!

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by dbstr » Sat Nov 21, 2009 7:01 pm

I thought you moved your cart to the header, so it won't work for you. I'll see if I can find the time to find another solution..

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by ThePath » Sat Nov 21, 2009 10:14 pm

Yes I did, so I was thinking I would have to change this: #module_cart .middle to #header .cart or whatever my names are?

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by dbstr » Sat Nov 21, 2009 10:17 pm

Yeah, I think that would work ;-)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by ThePath » Sun Nov 22, 2009 10:02 pm

i bdstr and anybody else interested in this problem.

OK so we have some progress. I have done two things that kinda half work...

In the cart.tpl ajax the following code is found:

Code: Select all

success: function (html) {
$('#module_cart .middle').html(html);
},
If I then enter the position of my cart in the header so it looks like this:

Code: Select all

success: function (html) {
$('#module_cart .middle').html(html);
$('#header .div6').html(html);
},
This way retains the ajax animation and updates both carts (one in left column and one in top right of header. However it takes out my code in the header (which displays "Basket: £Sub_Total") and replaces it with: "Sub-Total: £Sub_totoal". Im guessing it takes the styling/setting from the cart and plonks it in the header. So it updates it but changes the text/styling etc to what the cart has. Like I said half way there! Note when page is refreshed or you move to another page it returns to what I want.

The second thing I did was to copy a section of the ajax function:

Code: Select all

$('#add_to_cart').click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#product :input'),
			success: function (html) {
				$('#module_cart .middle').html(html);
			},


and stuck it at the bottom of the whole function so it reads:

Code: Select all

$('#add_to_cart').click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#product :input'),
			success: function (html) {
				$('#header .div6').html(html);
			},	
		});
This updates both subtotals but you dont get the ajax animation and once the add to cart button is pushed it goes straight to the basket to view items. Obviously becasue the screen changes the header cart section looks the way I want but I dont particularly want people to visit the basket everytime they add something to it?

ANybody got any ideas....my ajax knowledge is nill? O0

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by ThePath » Tue Nov 24, 2009 1:12 am

No ajax masters present then? :'(

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by harryo40 » Wed Dec 02, 2009 6:30 pm

Hi all,
Did you finally manage to resolve the updating of your cart in the header?
If not, take a look at the store i have done www.next2nowt.com & if what i have working (cart updating in header) is what your looking at then maybe i could help you guys out ;)
If its not what your looking at doing then ive read this post wrong...lol
cheers
h

Add To Cart Confirm Ajax Popup for OC 1.5.1.3 --> 1.5.5.1 - Add to Cart Confirmation Popup
Image Map Banner Module - Image Map Banner Module
----------------------------------------------------------------------
Womens Famous Name Fashion Clothing at bargain prices - Next2nowt.com


Active Member

Posts

Joined
Wed Oct 21, 2009 3:37 am
Location - Blackburn, Lancashire

Post by fido-x » Wed Dec 02, 2009 10:17 pm

In "catalog/controller/checkout/cart.php", find the following (lines 36-38):-

Code: Select all

if (isset($this->request->post['redirect'])) {
	$this->session->data['redirect'] = $this->request->post['redirect'];
}
with:

Code: Select all

$this->redirect(html_entity_decode($_SERVER['HTTP_REFERER']));
This should fix your redirect issue and redirect to the page your on.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by Qphoria » Wed Dec 02, 2009 10:38 pm

fido-x wrote:In "catalog/controller/checkout/cart.php", find the following (lines 36-38):-

Code: Select all

if (isset($this->request->post['redirect'])) {
	$this->session->data['redirect'] = $this->request->post['redirect'];
}
with:

Code: Select all

$this->redirect(html_entity_decode($_SERVER['HTTP_REFERER']));
This should fix your redirect issue and redirect to the page your on.
If you refresh the page, then doesn't the referer page become itself?

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by fido-x » Wed Dec 02, 2009 10:55 pm

ThePath wrote:... and once the add to cart button is pushed it goes straight to the basket to view items. Obviously becasue the screen changes the header cart section looks the way I want but I dont particularly want people to visit the basket everytime they add something to it?
Clicking the "Add to Cart" button loads the "checkout/cart" page. Adding the posted code will redirect you back to the page you were on when you clicked the button - no refresh needed.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by fido-x » Wed Dec 02, 2009 11:19 pm

Follow up. The only problem you should encounter using the aforementioned code, relates to the "Continue Shopping" button. If you go to the shopping cart page and update any details, then the shopping cart becomes the referrer, so you'll also need to change the following (lines 162-168) from:-

Code: Select all

if (isset($this->session->data['redirect'])) {
	$this->data['continue'] = $this->session->data['redirect'];

	unset($this->session->data['redirect']);
} else {
	$this->data['continue'] = $this->url->http('common/home');
}
to:

Code: Select all

if (isset($this->session->data['redirect'])) {
	$this->data['continue'] = $this->session->data['redirect'];

	unset($this->session->data['redirect']);
} else {
	if ($_SERVER['HTTP_REFERER'] == $this->url->http('checkout/cart')) {
		$this->data['continue'] = $this->url->http('common/home');
	} else {
		$this->data['continue'] = html_entity_decode($_SERVER['HTTP_REFERER']);
	}
}

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by ThePath » Fri Dec 04, 2009 7:49 am

@harry - Yeh I like your solution will you share how you did it? Does your solution involve moving the whole cart module to the header? As I havent done this, I still have the cart module in sidebar at moment but really like your solution.

@everyone else, thanks for all your input so far. The bodge I have come upwith which works ok is sticking this code at bottom of ajax function:

Code: Select all

setInterval(function() {  

     $("#div6").load(location.href+" #div6>*","");  

}, 3000); 
It aint to pretty but better than what I had and it works ;D

Image

OpenCart Theme Options - See All My Extensions - OpenCart Themes and Mods


User avatar
Active Member

Posts

Joined
Fri Jun 26, 2009 11:53 pm
Location - Scotland

Post by harryo40 » Sun Dec 06, 2009 3:06 am

Hi,
I have just today put all my files etc in folders & zipped them up for OC 1.3.4 to show the cart in the header with view cart / sub-total + item count + the ajax animation of an item to the header & its uploaded for people to try out & experiment with but read the 'READ ME' txt file 1st. Go to the contributions section of OC & its in the 'Modules' section under 'cart in header'
cheers
h

Add To Cart Confirm Ajax Popup for OC 1.5.1.3 --> 1.5.5.1 - Add to Cart Confirmation Popup
Image Map Banner Module - Image Map Banner Module
----------------------------------------------------------------------
Womens Famous Name Fashion Clothing at bargain prices - Next2nowt.com


Active Member

Posts

Joined
Wed Oct 21, 2009 3:37 am
Location - Blackburn, Lancashire
Who is online

Users browsing this forum: No registered users and 2 guests