How To Show Count/Number Of Added Items In Cart Anywhere In OpenCart

Hi Friends, As I told you that in my last post that I will share some post about open cart. In this post I am sharing you how to show a count of added items in your cart. means you can show at top or anywhere on your page that you have number of items in your cart. I have searched about this if open cart have this function already but I didn’t find anything, So I used my technique to do this. So if you are interested to do this then you can follow steps shown below :

1. Open Catalog -> controller -> checkout -> cart.php file.

2. Find below code

$this->data['products'] = array();

and paste this code below it.

if(count($this->cart->getProducts()))
			$_SESSION['count_2'] = count($this->cart->getProducts());

3. Find this code

$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
    	} else {

and paste this code below it.

$_SESSION['count_2'] = "";

4. Now to show added items count just paste below code anywhere you want to show items count.

isset($_SESSION["count_2"]))
{
echo $_SESSION["count_2"];
} else echo '0';?> items

It will show items count if you have added any items in your cart and if you have not added any items then it will show “0 items”.

I think this article helps you. Please make comment if you like it or you need any help.