  |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2004 osCommerce |
| |
| 8 | + | Copyright (c) 2007 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | This program is free software; you can redistribute it and/or modify |
| |
11 | 11 | | it under the terms of the GNU General Public License v2 (1991) |
| |
|
|
 |
… |
|
15 | 15 | | require('../includes/classes/category_tree.php'); |
| |
16 | 16 | | |
| |
17 | 17 | | class osC_CategoryTree_Admin extends osC_CategoryTree { |
  |
18 | | - | var $show_category_product_count = true; |
| |
| 18 | + | protected $_show_total_products = true; |
|
19 | 19 | | |
  |
20 | | - | function osC_CategoryTree_Admin() { |
| |
| 20 | + | function __constructor() { |
|
21 | 21 | | global $osC_Database, $osC_Language; |
| |
22 | 22 | | |
| |
23 | 23 | | $Qcategories = $osC_Database->query('select c.categories_id, c.parent_id, c.categories_image, cd.categories_name from :table_categories c, :table_categories_description cd where c.categories_id = cd.categories_id and cd.language_id = :language_id order by c.parent_id, c.sort_order, cd.categories_name'); |
| |
|
|
 |
… |
|
26 | 26 | | $Qcategories->bindInt(':language_id', $osC_Language->getID()); |
| |
27 | 27 | | $Qcategories->execute(); |
| |
28 | 28 | | |
  |
29 | | - | $this->data = array(); |
| |
| 29 | + | $this->_data = array(); |
|
30 | 30 | | |
| |
31 | 31 | | while ($Qcategories->next()) { |
  |
32 | | - | $this->data[$Qcategories->valueInt('parent_id')][$Qcategories->valueInt('categories_id')] = array('name' => $Qcategories->value('categories_name'), 'image' => $Qcategories->value('categories_image'), 'count' => 0); |
| |
| 32 | + | $this->_data[$Qcategories->valueInt('parent_id')][$Qcategories->valueInt('categories_id')] = array('name' => $Qcategories->value('categories_name'), 'image' => $Qcategories->value('categories_image'), 'count' => 0); |
|
33 | 33 | | } |
| |
34 | 34 | | |
| |
35 | 35 | | $Qcategories->freeResult(); |
| |
36 | 36 | | |
  |
37 | | - | if ($this->show_category_product_count === true) { |
| |
38 | | - | $this->calculateCategoryProductCount(); |
| |
| 37 | + | if ($this->_show_total_products === true) { |
| |
| 38 | + | $this->_calculateProductTotals(false); |
|
39 | 39 | | } |
| |
40 | 40 | | } |
| |
41 | 41 | | |
  |
42 | | - | function calculateCategoryProductCount() { |
| |
43 | | - | global $osC_Database; |
| |
44 | | - | |
| |
45 | | - | $totals = array(); |
| |
46 | | - | |
| |
47 | | - | $Qtotals = $osC_Database->query('select p2c.categories_id, count(*) as total from :table_products p, :table_products_to_categories p2c where p2c.products_id = p.products_id group by p2c.categories_id'); |
| |
48 | | - | $Qtotals->bindTable(':table_products', TABLE_PRODUCTS); |
| |
49 | | - | $Qtotals->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); |
| |
50 | | - | $Qtotals->execute(); |
| |
51 | | - | |
| |
52 | | - | while ($Qtotals->next()) { |
| |
53 | | - | $totals[$Qtotals->valueInt('categories_id')] = $Qtotals->valueInt('total'); |
| |
54 | | - | } |
| |
55 | | - | |
| |
56 | | - | $Qtotals->freeResult(); |
| |
57 | | - | |
| |
58 | | - | foreach ($this->data as $parent => $categories) { |
| |
59 | | - | foreach ($categories as $id => $info) { |
| |
60 | | - | if (isset($totals[$id]) && ($totals[$id] > 0)) { |
| |
61 | | - | $this->data[$parent][$id]['count'] = $totals[$id]; |
| |
62 | | - | |
| |
63 | | - | $parent_category = $parent; |
| |
64 | | - | while ($parent_category != $this->root_category_id) { |
| |
65 | | - | foreach ($this->data as $parent_parent => $parent_categories) { |
| |
66 | | - | foreach ($parent_categories as $parent_category_id => $parent_category_info) { |
| |
67 | | - | if ($parent_category_id == $parent_category) { |
| |
68 | | - | $this->data[$parent_parent][$parent_category_id]['count'] += $this->data[$parent][$id]['count']; |
| |
69 | | - | |
| |
70 | | - | $parent_category = $parent_parent; |
| |
71 | | - | break 2; |
| |
72 | | - | } |
| |
73 | | - | } |
| |
74 | | - | } |
| |
75 | | - | } |
| |
76 | | - | } |
| |
77 | | - | } |
| |
78 | | - | } |
| |
79 | | - | |
| |
80 | | - | unset($totals); |
| |
81 | | - | } |
| |
82 | | - | |
|
83 | 42 | | function getPath($category_id, $level = 0, $separator = ' ') { |
| |
84 | 43 | | $path = ''; |
| |
85 | 44 | | |
  |
86 | | - | foreach ($this->data as $parent => $categories) { |
| |
| 45 | + | foreach ($this->_data as $parent => $categories) { |
  |
87 | 46 | | foreach ($categories as $id => $info) { |
| |
88 | 47 | | if ($id == $category_id) { |
| |
89 | 48 | | if ($level < 1) { |