Page 1 of 1

SOLVED! How to show total quantity of items in admin?

Posted: Sun Aug 14, 2011 12:33 am
by harryo40
I am after showing the total quantity of items in admin?
When logged in to admin, it shows the total number products like this...
Showing 1 to 100 of 3463 (35 Pages) - at the bottom of the page & also in the admin>>dashboard, but I am after also seeing the total quantity of items for example, 1 product might have a quantity of 10 & another may have a quantity of 20 & so on.
Any help is appreciated ;)

Re: How to show total quantity of items in admin?

Posted: Tue Aug 16, 2011 8:12 pm
by harryo40
I didnt think this would be to difficult to do but I have got a little further ;)
I have now managed to use the following SQL to show me the total quantity of item from within myphp

Code: Select all

SELECT SUM( quantity ) AS "Total Items" FROM product;
& this shows me the total items (not total products) as shown in the image below.
When I click create PHP code, it shows me

Code: Select all

$sql = "SELECT SUM( quantity ) AS \"Total Items\" FROM product";
& all i need to know now is, how to display this on the Dashboard of Admin, in the overview part ???

Re: How to show total quantity of items in admin?

Posted: Wed Aug 17, 2011 1:48 am
by harryo40
Solved!
Added to model->product.php

Code: Select all

public function getTotalQuantity($data = array()) {
		$sql = "SELECT SUM( quantity ) AS total FROM product";

		$query = $this->db->query($sql);
		
		return $query->row['total'];
	}
& also added appropriate codes to home.php in Controller / Language / View

Re: SOLVED! How to show total quantity of items in admin?

Posted: Fri Sep 02, 2011 8:00 am
by mkh
Hmm, how do I get this to work ?

Really need the total product amount to show up on the admin front page ....

Re: SOLVED! How to show total quantity of items in admin?

Posted: Mon Sep 05, 2011 5:28 pm
by harryo40
mkh wrote:Hmm, how do I get this to work ?

Really need the total product amount to show up on the admin front page ....
What version of OC are you after this working in because I did this for 1.4.9.1

Re: SOLVED! How to show total quantity of items in admin?

Posted: Tue Sep 06, 2011 1:25 am
by mkh
What version of OC are you after this working in because I did this for 1.4.9.1
I'm using 1.5.1.1

Re: SOLVED! How to show total quantity of items in admin?

Posted: Wed Sep 07, 2011 1:15 am
by harryo40
mkh wrote:I'm using 1.5.1.1
Hi mkh,
Have you made any adjustments to the layout in admin?
I have just tried the same method on my demo page using 1.5.1.1 & it works fine.
You need to open & edit all the following files with the extra codes...
Open Admin->Controller->Common->home.php & Find...

Code: Select all

$this->data['total_order'] = $this->model_sale_order->getTotalOrders();
& after add (next line)...

Code: Select all

		$this->load->model('catalog/product');
		$this->data['total_quantity'] = $this->model_catalog_product->getTotalQuantity();
Then open Admin->Language->Common->home.php find...

Code: Select all

$_['text_total_order']              = 'Total Orders:';
& after add...

Code: Select all

$_['text_total_quantity']           = 'Total items:';
Then in Admin->Model->Catalog->Product.php find...

Code: Select all

	public function getTotalProductsByStockStatusId($stock_status_id) {
then BEFORE that line add...

Code: Select all

	public function getTotalQuantity($data = array()) {
		$sql = "SELECT SUM( quantity ) AS total FROM product";

		$query = $this->db->query($sql);
		
		return $query->row['total'];
	}
& finally open Admin->View->Template->Common->home.tpl & find...

Code: Select all

            <tr>
              <td><?php echo $text_total_order; ?></td>
              <td><?php echo $total_order; ?></td>
            </tr>
then after add...

Code: Select all

            <tr>
              <td><?php echo $text_total_quantity; ?></td>
              <td align="right"><?php echo $total_quantity; ?></td>
            </tr>
            <tr>
This will show an extra line called 'Total Items' in admin front page (Dashboard) & below Total Orders ;)
If you havn't made any changes to the Admin side of OC1.5.1.1 I can put this together so you would just need to upload the folder & it will install the code ;) otherwise, the above way is the manual way.

Re: SOLVED! How to show total quantity of items in admin?

Posted: Wed Sep 07, 2011 1:35 am
by mkh
harryo40 : Thank you SO much, I could not make the lang file work, so just added the title myself, but it works, thanks again...

/mkh

Re: SOLVED! How to show total quantity of items in admin?

Posted: Wed Sep 07, 2011 1:36 am
by harryo40
Glad to have helped ;)

Re: SOLVED! How to show total quantity of items in admin?

Posted: Wed Sep 07, 2011 1:46 am
by mkh
Okay, found a tiny bug, this should work perfect.

Code: Select all

	public function getTotalQuantity($data = array()) {
	      $query = $this->db->query("SELECT count(*) AS total FROM " . DB_PREFIX . "product");

	      return $query->row['total'];
	   }

Re: SOLVED! How to show total quantity of items in admin?

Posted: Wed Sep 07, 2011 1:54 am
by harryo40
Yep I forgot I only moved the coding over from 1.4.9.1 to 1.5.1.1 & without changing any of it, but at least it works & shows you what you wanted ;)