Page 2 of 2
Re: [How-to] Display cart total (items & price) in header
Posted: Mon Nov 29, 2010 8:42 am
by jolo
Wow thank you so much for this! Loving the opencart community!
Re: [How-to] Display cart total (items & price) in header
Posted: Wed Dec 15, 2010 7:42 pm
by waseem
This gives following error at my cart when going to login/register page. Please help to fix this.
Code: Select all
Fatal error: Call to a member function rewrite() on a non-object in D:\wamp\www\store\catalog\controller\common\header.php on line 25
using oc version 1.4.7
Thanks
Waseem
Re: [How-to] Display cart total (items & price) in header
Posted: Sat Jan 01, 2011 1:14 am
by Chones
There's actually a much easier way that hardly changes any core files. I posted the solution on my blog:
http://craigmurray.me.uk/opencart-mods/ ... -opencart/
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 6:11 am
by Maansy
Nice alternative method
Good job

Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 6:25 pm
by tessed
Craig,
I have tried your solution, but the cart is not showing after adding a product to the cart. I have check and double checked cart.php, stylesheet.css, header.tpl and the code in ajax_add.js .
I understand php, but don't see no errors. Only changes i have made are that my div for the cart has another name. This new name i have edited in the cart.php code.
Hope someone can help.
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 6:31 pm
by Chones
You'll need to also change all references to #cart_in_header in the Ajax code too.
Although why not just use the code as it was originally - it works fine.
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 6:39 pm
by tessed
Sorry, that is what i meant, the ajax file.
The strange thing is that when i call minicart directly in the browser it does show the cart.
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 6:58 pm
by Chones
I'd go back to the original files and try them without changes.
If it works fine then it is a change you have made somewhere to the code.
If it doesn't work, then it may be something elsewhere, such as some other Ajax or Jquery in your template.
That's all I can suggest I'm afraid.
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 8:16 pm
by tessed
It was the ajax_add.js file not being added to the header. Very strange, i thought this ajax file was already being used in the default template, guess it wasn't.
But now, the cart appears when a product is added, but when you go to another page then the minicart dissapears.
Re: [How-to] Display cart total (items & price) in header
Posted: Sun Jan 02, 2011 9:12 pm
by Chones
You need to have this in your header.tpl so that the cart is always there.
Code: Select all
<div id="cart_in_header">
<?php
$cart_number = $this->cart->countProducts();
if ($cart_number == 1) {echo "1 item in shopping cart";}
else {echo $cart_number." items in shopping cart";}
echo"<br />";
echo "Total: ".$this->currency->format($this->cart->getTotal());
?>
echo"<br />";
<a href="index.php?route=checkout/cart">View Cart</a> |
<a href="index.php?route=checkout/shipping">Checkout</a>
</div>
Please follow the instructions accurately before trying to change things
Re: [How-to] Display cart total (items & price) in header
Posted: Mon Jan 03, 2011 2:15 am
by tessed
I didn't understand how it works to have the same code 2 times, but now I see it just works. Thank you for the help.
Re: [How-to] Display cart total (items & price) in header
Posted: Thu Apr 09, 2015 12:01 pm
by meistralf
Hi. How to minimize the list of item at header "shopping cart : 0 item(s) - RM0.00" ?
because it become too long list when i add to many item.