Changeset 17557
- Timestamp:
- 2008/08/26 13:24:44 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/comu-ver2/data/class/helper/SC_Helper_DB.php
r17553 r17557 913 913 */ 914 914 function sfCategory_Count($objQuery){ 915 $sql = "";916 915 917 916 //テーブル内容の削除 … … 919 918 $objQuery->query("DELETE FROM dtb_category_total_count"); 920 919 921 //各カテゴリ内の商品数を数えて格納 922 $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) "; 923 $sql .= " SELECT T1.category_id, count(T2.category_id), now() "; 924 $sql .= " FROM dtb_category AS T1 LEFT JOIN dtb_product_categories AS T2"; 925 $sql .= " ON T1.category_id = T2.category_id "; 926 $sql .= " LEFT JOIN vw_products_allclass_detail AS alldtl"; 927 $sql .= " ON T2.product_id = alldtl.product_id"; 928 $sql .= " WHERE alldtl.del_flg = 0 AND alldtl.status = 1 "; 929 920 $sql_where .= 'alldtl.del_flg = 0 AND alldtl.status = 1'; 930 921 // 在庫無し商品の非表示 931 922 if (NOSTOCK_HIDDEN === true) { 932 $sql .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; 933 } 923 $sql_where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; 924 } 925 926 //各カテゴリ内の商品数を数えて格納 927 $sql = <<< __EOS__ 928 INSERT INTO dtb_category_count(category_id, product_count, create_date) 929 SELECT T1.category_id, count(T2.category_id), now() 930 FROM dtb_category AS T1 931 LEFT JOIN dtb_product_categories AS T2 932 ON T1.category_id = T2.category_id 933 LEFT JOIN vw_products_allclass_detail AS alldtl 934 ON T2.product_id = alldtl.product_id 935 WHERE $sql_where 936 GROUP BY T1.category_id, T2.category_id 937 __EOS__; 934 938 935 $sql .= " GROUP BY T1.category_id, T2.category_id ";936 939 $objQuery->query($sql); 937 940 938 941 //子カテゴリ内の商品数を集計する 939 940 // 最下層(level=5)のカテゴリから順に足し合わせていく。 941 for ($i = 5; $i >= 1; --$i) { 942 943 // カテゴリ情報を取得 944 $arrCat = $objQuery->select('category_id', 'dtb_category'); 945 946 foreach ($arrCat as $row) { 947 $category_id = $row['category_id']; 948 $arrval = array(); 949 950 $arrval[] = $category_id; 951 952 list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id); 953 if ($tmp_where != "") { 954 $sql_where_product_ids = "alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; 955 $arrval = array_merge((array)$arrval, (array)$tmp_arrval); 956 } else { 957 $sql_where_product_ids = '0<>0'; // 一致させない 958 } 959 942 960 $sql = <<< __EOS__ 943 961 INSERT INTO dtb_category_total_count (category_id, product_count, create_date) 944 SELECT category_id, SUM(product_count), NOW() 945 FROM 946 ( 947 SELECT T1.parent_category_id AS category_id, T2.product_count 948 FROM dtb_category AS T1, dtb_category_total_count AS T2 949 WHERE T2.category_id = T1.category_id AND T1.level = ? 950 UNION ALL 951 SELECT T3.category_id, T4.product_count 952 FROM dtb_category AS T3, dtb_category_count AS T4 953 WHERE T4.category_id = T3.category_id AND T3.level = ? 954 ) AS T5 955 GROUP BY category_id; 962 SELECT 963 ? 964 ,count(*) 965 ,now() 966 FROM vw_products_allclass_detail AS alldtl 967 WHERE ($sql_where) AND ($sql_where_product_ids) 956 968 __EOS__; 957 $objQuery->query($sql, array($i+1, $i)); 958 } 959 960 // データの構成を改修前と同じにするための処理(不要?) 961 $sql = " INSERT INTO dtb_category_total_count (category_id, product_count, create_date) "; 962 $sql .= " SELECT category_id, NULL, NOW() FROM dtb_category AS T1 "; 963 $sql .= " WHERE NOT EXISTS(SELECT * FROM dtb_category_total_count "; 964 $sql .= " WHERE category_id = T1.category_id); "; 965 966 $objQuery->query($sql); 969 970 $objQuery->query($sql, $arrval); 971 } 967 972 } 968 973
Note: See TracChangeset
for help on using the changeset viewer.