Code Duplication    Length = 19-22 lines in 2 locations

catalog/admin/includes/functions/general.php 1 location

@@ 598-619 (lines=22) @@
595
////
596
// Count how many products exist in a category
597
// TABLES: products, products_to_categories, categories
598
  function tep_products_in_category_count($categories_id, $include_deactivated = false) {
599
    $products_count = 0;
600
601
    if ($include_deactivated) {
602
      $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$categories_id . "'");
603
    } else {
604
      $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$categories_id . "'");
605
    }
606
607
    $products = tep_db_fetch_array($products_query);
608
609
    $products_count += $products['total'];
610
611
    $childs_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$categories_id . "'");
612
    if (tep_db_num_rows($childs_query)) {
613
      while ($childs = tep_db_fetch_array($childs_query)) {
614
        $products_count += tep_products_in_category_count($childs['categories_id'], $include_deactivated);
615
      }
616
    }
617
618
    return $products_count;
619
  }
620
621
////
622
// Count how many subcategories exist in a category

catalog/includes/functions/general.php 1 location

@@ 398-416 (lines=19) @@
395
////
396
// Return the number of products in a category
397
// TABLES: products, products_to_categories, categories
398
  function tep_count_products_in_category($category_id, $include_inactive = false) {
399
    $products_count = 0;
400
    if ($include_inactive == true) {
401
      $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p2c.categories_id = '" . (int)$category_id . "'");
402
    } else {
403
      $products_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c where p.products_id = p2c.products_id and p.products_status = '1' and p2c.categories_id = '" . (int)$category_id . "'");
404
    }
405
    $products = tep_db_fetch_array($products_query);
406
    $products_count += $products['total'];
407
408
    $child_categories_query = tep_db_query("select categories_id from " . TABLE_CATEGORIES . " where parent_id = '" . (int)$category_id . "'");
409
    if (tep_db_num_rows($child_categories_query)) {
410
      while ($child_categories = tep_db_fetch_array($child_categories_query)) {
411
        $products_count += tep_count_products_in_category($child_categories['categories_id'], $include_inactive);
412
      }
413
    }
414
415
    return $products_count;
416
  }
417
418
////
419
// Return true if the category has subcategories