Page 1 of 1

Count orders by order status

Posted: Sun Nov 18, 2018 5:47 am
by teodorl
Hello guys!

I want to count my orders by status (/admin->sales). I've manage to create some buttons with orders status and I want to insert a counter Pending (x), Canceled (y), Finish (z),...
I've tried to do this using $history_total attribute from pagination but I didn't manage to solve it.
Can you please help me with a solution?

*php newbie :)

Re: Count orders by order status

Posted: Tue Dec 04, 2018 7:00 pm
by teodorl
Some help, please

Re: Count orders by order status

Posted: Wed Dec 05, 2018 1:36 am
by IP_CAM
Well, some of them exist already for 1.5.6.x Versions! ;)
And they all work well upto OC v.1.5.6.5_rc as well. But not all
of them look exactly like shown on the images below, because
I usually change a few details in my 'final' versions... :D
But for anything else, you'll have to get professional Support.
Ernie
---
Orders Statuses Report
https://www.opencart.com/index.php?rout ... n_id=13495
---
Multiple select option for Order status in Sales Report
https://www.opencart.com/index.php?rout ... n_id=17321
---
Custom Sales Reports
https://www.opencart.com/index.php?rout ... n_id=10022
---
Order List
https://www.opencart.com/index.php?rout ... on_id=3597
---
Image

Re: Count orders by order status

Posted: Wed Dec 05, 2018 4:23 pm
by teodorl
Hello! Thanks for your answer, nice work but I don't need this. All I want is to show how many orders do I have in the Sales area. I have something like this:
Image

Every button is one order status and if you click it will show you the orders with that status.

Re: Count orders by order status

Posted: Thu Dec 20, 2018 4:57 pm
by teodorl
Up!

Re: Count orders by order status

Posted: Fri Dec 21, 2018 1:42 am
by Johnathan
You don't need a report or custom extension for this. Just filter on a particular order status in Sales > Orders, then look at the bottom pagination to see the total number of orders with that status. If you want to add some links to those pages yourself, you can do that with normal <a> tags in HTML.

Re: Count orders by order status

Posted: Fri Dec 21, 2018 4:17 pm
by teodorl
I've managed to do the links for every button but I didn't manage to put the counter for every link before you click it. I want to put a counter for every button (status order) so that I don't have to click the button to find out how many orders with that status are.

Code: Select all

<div class="tab">
		  <button onclick ="filter_status(this);" class="tablinks" value="0">Toate comenzile</button>
		  <button onclick ="filter_status(this);" class="tablinks" value="30">Comenzi Lipsa</button>
	   <?php foreach ($order_statuses as $order_status) { ?>
			<button onclick ="filter_status(this);" class="tablinks" id="q_<?php echo $order_status['order_status_id']; ?>" value="<?php echo $order_status['order_status_id']; ?>"><?php
					if($order_status['name'] == 'Finalizata') {echo '<span class="instoc"> </span>'; }
					if($order_status['name'] == 'In procesare') {echo '<span class="inprocesare"> </span>'; }
					if($order_status['name'] == 'Anulata') {echo '<span class="anulata"> </span>'; }
					if($order_status['name'] == 'Nepreluata') {echo '<span class="nepreluata"> </span>'; }
					if($order_status['name'] == 'Ridicare de la sediu') {echo '<span class="ridsediu"> </span>'; }
					if($order_status['name'] == 'Asteptare plata OP') {echo '<span class="plataop"> </span>'; }
					if($order_status['name'] == 'Plata card esuata') {echo '<span class="expirata"> </span>'; }
					if($order_status['name'] == 'Stornata') {echo '<span class="stornata"> </span>'; }
					if($order_status['name'] == 'Pregatita de Livrare') {echo '<img src="/image/data/prompt-service-clima-favicon.png" style="height:14px;display:inline-block;margin: 0 5px 0 0;" />'; }
					if($order_status['name'] == 'Pregatita de Trimis') {echo '<img src="/image/data/FANCourier.png" style="height:14px;display:inline-block;margin: 0 5px 0 0;" />'; }
					if($order_status['name'] == 'Platita online') {echo '<img src="/image/data/favicon-euplatesc.png" style="height:14px;display:inline-block;margin: 0 5px 0 0;" />'; }
					if($order_status['name'] == 'Plata card nefinalizata') {echo '<span class="cnefinal"> </span>'; }
				?><?php echo $order_status['name'].' ('.count(HERE I DON'T KNOW WHAT IS THE CODE).')'; ?></button>
	   <?php } ?>
				  
	  </div>

Re: Count orders by order status

Posted: Fri Dec 21, 2018 11:33 pm
by Johnathan
That's much more complicated. You'll need to do some database queries in the controller file, set those values in a variable or array, then pass that forward to the template file. It's beyond what I can suggest code for, but if you know how the OpenCart MVC system works, you should be able to figure it out.

Re: Count orders by order status

Posted: Thu Jan 03, 2019 10:45 pm
by teodorl
I'll appreciate any help from you with the code.

Re: Count orders by order status

Posted: Thu Jan 03, 2019 11:42 pm
by Johnathan
Controller files are located in /admin/controller/. You'd find the relevant file (usually it's based on the "route" of the page, so you can try finding it that way) and then you'd do a database query like this:

$my_query = $this->db->query("YOUR MYSQL HERE");

Then, you'd use whatever data you got from that query and put it in a variable like this:

$this->data['my_var'] = 'Some Data';

Once you've done that, you can use the variable in your template file, like this:

<?php echo $my_var; ?>

Hope that helps