Changeset 17286


Ignore:
Timestamp:
2008/04/24 17:01:49 (16 years ago)
Author:
shutta
Message:

fix for #289

File:
1 edited

Legend:

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

    r17284 r17286  
    915915 
    916916        //子カテゴリ内の商品数を集計する 
    917         $arrCat = $objQuery->getAll("SELECT * FROM dtb_category"); 
    918  
    919         $sql = ""; 
    920         foreach($arrCat as $key => $val){ 
    921  
    922             // 子ID一覧を取得 
    923             $arrRet = $this->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']); 
    924             $line = SC_Utils_Ex::sfGetCommaList($arrRet); 
    925  
    926             $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) "; 
    927             $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count "; 
    928             $sql .= " WHERE category_id IN (" . $line . ")"; 
    929  
    930             $objQuery->query($sql, array($val['category_id'])); 
    931         } 
     917 
     918        // 最下層(level=5)のカテゴリから順に足し合わせていく。 
     919        for ($i = 5; $i >= 1; --$i) { 
     920            $sql = " INSERT INTO dtb_category_total_count (category_id, product_count, create_date) "; 
     921            $sql .= " SELECT category_id, SUM(product_count), NOW() "; 
     922            $sql .= " FROM (SELECT T1.parent_category_id AS category_id, T2.product_count "; 
     923            $sql .= " FROM dtb_category AS T1, dtb_category_total_count AS T2 "; 
     924            $sql .= " WHERE T2.category_id = T1.category_id AND T1.level = ? "; 
     925            $sql .= " UNION ALL SELECT T3.category_id, T4.product_count "; 
     926            $sql .= " FROM dtb_category AS T3, dtb_category_count AS T4 "; 
     927            $sql .= " WHERE T4.category_id = T3.category_id AND T3.level = ?) AS T5 "; 
     928            $sql .= " GROUP BY category_id; "; 
     929 
     930            $objQuery->query($sql, array($i+1, $i)); 
     931        } 
     932 
     933        // データの構成を改修前と同じにするための処理(不要?) 
     934        $sql = " INSERT INTO dtb_category_total_count (category_id, product_count, create_date) "; 
     935        $sql .= " SELECT category_id, NULL, NOW() FROM dtb_category AS T1 "; 
     936        $sql .= " WHERE NOT EXISTS(SELECT * FROM dtb_category_total_count "; 
     937        $sql .= " WHERE category_id = T1.category_id); "; 
     938 
     939        $objQuery->query($sql); 
    932940    } 
    933941 
Note: See TracChangeset for help on using the changeset viewer.