Creating Live Product In Cart Count in header .tpl
Posted: Tue Sep 19, 2017 7:59 pm
Hi All,
I am working on an adaptation of the stock theme for a slightly more compact view on mobiles. To get everything to display nice I need to show a count of products in the cart outside of the standard id="cart" button.
I want to show a simple count of how many products are in the cart (no monetary total etc, just how many products are in the cart)
I have this working using the following code:
In catalogue/common/header.php
Then in the header.tpl
this works but, does not offer the functionality of updating as soon as a product is put in the cart. It shows the correct count of products, but only when the next page is loaded.
Would anyone be able to point me in the right direction of how to make this update as soon as anyone hits the "add to cart" button or updates cart totals? I am assuming that something in common.js needs updating? ive played around with it but cannot get it to work still.
I am on opencart 2.1.0.2 if that makes any odds.
Cheers!
James
I am working on an adaptation of the stock theme for a slightly more compact view on mobiles. To get everything to display nice I need to show a count of products in the cart outside of the standard id="cart" button.
I want to show a simple count of how many products are in the cart (no monetary total etc, just how many products are in the cart)
I have this working using the following code:
In catalogue/common/header.php
Code: Select all
//how many things in cart
$data['cartcount'] = $this->cart->countProducts();
Code: Select all
<?php if (isset ($cartcount)) { echo $cartcount; } ?>
Would anyone be able to point me in the right direction of how to make this update as soon as anyone hits the "add to cart" button or updates cart totals? I am assuming that something in common.js needs updating? ive played around with it but cannot get it to work still.
I am on opencart 2.1.0.2 if that makes any odds.
Cheers!
James