  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: category_tree.php 377 2006-01-09 14:47:49Z hpdl $ |
| |
| 3 | + | $Id: category_tree.php 621 2006-07-16 14:16:00Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
257 | 257 | | } |
| |
258 | 258 | | |
| |
259 | 259 | | function calculateCategoryProductCount() { |
  |
| 260 | + | global $osC_Database; |
| |
| 261 | + | |
| |
| 262 | + | $totals = array(); |
| |
| 263 | + | |
| |
| 264 | + | $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 and p.products_status = :products_status group by p2c.categories_id'); |
| |
| 265 | + | $Qtotals->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 266 | + | $Qtotals->bindTable(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); |
| |
| 267 | + | $Qtotals->bindInt(':products_status', 1); |
| |
| 268 | + | $Qtotals->execute(); |
| |
| 269 | + | |
| |
| 270 | + | while ($Qtotals->next()) { |
| |
| 271 | + | $totals[$Qtotals->valueInt('categories_id')] = $Qtotals->valueInt('total'); |
| |
| 272 | + | } |
| |
| 273 | + | |
| |
| 274 | + | $Qtotals->freeResult(); |
| |
| 275 | + | |
|
260 | 276 | | foreach ($this->data as $parent => $categories) { |
| |
261 | 277 | | foreach ($categories as $id => $info) { |
  |
262 | | - | $this->data[$parent][$id]['count'] = $this->countCategoryProducts($id); |
| |
| 278 | + | if ($totals[$id] > 0) { |
| |
| 279 | + | $this->data[$parent][$id]['count'] = $totals[$id]; |
|
263 | 280 | | |
  |
264 | | - | $parent_category = $parent; |
| |
265 | | - | while ($parent_category != $this->root_category_id) { |
| |
266 | | - | foreach ($this->data as $parent_parent => $parent_categories) { |
| |
267 | | - | foreach ($parent_categories as $parent_category_id => $parent_category_info) { |
| |
268 | | - | if ($parent_category_id == $parent_category) { |
| |
269 | | - | $this->data[$parent_parent][$parent_category_id]['count'] += $this->data[$parent][$id]['count']; |
| |
| 281 | + | $parent_category = $parent; |
| |
| 282 | + | while ($parent_category != $this->root_category_id) { |
| |
| 283 | + | foreach ($this->data as $parent_parent => $parent_categories) { |
| |
| 284 | + | foreach ($parent_categories as $parent_category_id => $parent_category_info) { |
| |
| 285 | + | if ($parent_category_id == $parent_category) { |
| |
| 286 | + | $this->data[$parent_parent][$parent_category_id]['count'] += $this->data[$parent][$id]['count']; |
|
270 | 287 | | |
  |
271 | | - | $parent_category = $parent_parent; |
| |
272 | | - | break 2; |
| |
| 288 | + | $parent_category = $parent_parent; |
| |
| 289 | + | break 2; |
| |
| 290 | + | } |
|
273 | 291 | | } |
| |
274 | 292 | | } |
| |
275 | 293 | | } |
| |
276 | 294 | | } |
| |
277 | 295 | | } |
| |
278 | 296 | | } |
  |
279 | | - | } |
|
280 | 297 | | |
  |
281 | | - | function countCategoryProducts($category_id) { |
| |
282 | | - | global $osC_Database; |
| |
283 | | - | |
| |
284 | | - | $Qcategories = $osC_Database->query('select count(*) as total from :table_products p, :table_products_to_categories p2c where p2c.categories_id = :categories_id and p2c.products_id = p.products_id and p.products_status = 1'); |
| |
285 | | - | $Qcategories->bindRaw(':table_products', TABLE_PRODUCTS); |
| |
286 | | - | $Qcategories->bindRaw(':table_products_to_categories', TABLE_PRODUCTS_TO_CATEGORIES); |
| |
287 | | - | $Qcategories->bindInt(':categories_id', $category_id); |
| |
288 | | - | $Qcategories->execute(); |
| |
289 | | - | |
| |
290 | | - | $count = $Qcategories->valueInt('total'); |
| |
291 | | - | |
| |
292 | | - | $Qcategories->freeResult(); |
| |
293 | | - | |
| |
294 | | - | return $count; |
| |
| 298 | + | unset($totals); |
  |
295 | 299 | | } |
| |
296 | 300 | | |
| |
297 | 301 | | function setRootCategoryID($root_category_id) { |