Ignore:
Timestamp:
2008/08/26 13:24:44 (16 years ago)
Author:
Seasoft
Message:

「子カテゴリ内の商品数を集計する」となっている部分のロジックが、実際には「カテゴリ登録数」となっていたので「商品数」に修正。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/helper/SC_Helper_DB.php

    r17553 r17557  
    913913     */ 
    914914    function sfCategory_Count($objQuery){ 
    915         $sql = ""; 
    916915 
    917916        //テーブル内容の削除 
     
    919918        $objQuery->query("DELETE FROM dtb_category_total_count"); 
    920919 
    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'; 
    930921        // 在庫無し商品の非表示 
    931922        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__; 
    934938         
    935         $sql .= " GROUP BY T1.category_id, T2.category_id "; 
    936939        $objQuery->query($sql); 
    937940 
    938941        //子カテゴリ内の商品数を集計する 
    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             
    942960            $sql = <<< __EOS__ 
    943961                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) 
    956968__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        } 
    967972    } 
    968973 
Note: See TracChangeset for help on using the changeset viewer.