- Timestamp:
- 2012/02/22 01:27:53 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/version-2_12-dev/data/class/helper/SC_Helper_DB.php
r21527 r21544 540 540 */ 541 541 function addProductBeforCategories($category_id, $product_id) { 542 $objQuery =& SC_Query_Ex::getSingletonInstance(); 542 543 543 544 $sqlval = array('category_id' => $category_id, 544 545 'product_id' => $product_id); 545 546 546 $objQuery =& SC_Query_Ex::getSingletonInstance(); 547 548 // 現在の商品カテゴリを取得 549 $arrCat = $objQuery->select('product_id, category_id, rank', 550 'dtb_product_categories', 551 'category_id = ?', 552 array($category_id)); 553 554 $max = '0'; 555 foreach ($arrCat as $val) { 556 // 同一商品が存在する場合は登録しない 557 if ($val['product_id'] == $product_id) { 558 return; 559 } 560 // 最上位ランクを取得 561 $max = ($max < $val['rank']) ? $val['rank'] : $max; 562 } 563 $sqlval['rank'] = $max + 1; 564 $objQuery->insert('dtb_product_categories', $sqlval); 547 $arrSql = array(); 548 $arrSql['rank'] = '(SELECT COALESCE(MAX(rank), 0) FROM dtb_product_categories sub WHERE category_id = ?) + 1'; 549 550 $from_and_where = $objQuery->dbFactory->getDummyFromClauseSql(); 551 $from_and_where .= ' WHERE NOT EXISTS(SELECT * FROM dtb_product_categories WHERE category_id = ? AND product_id = ?)'; 552 $objQuery->insert('dtb_product_categories', $sqlval, $arrSql, array($category_id), $from_and_where, array($category_id, $product_id)); 565 553 } 566 554 … … 711 699 } 712 700 701 unset($arrCategoryCountOld); 702 unset($arrCategoryCountNew); 703 713 704 $arrDiffCategory_id = array(); 714 705 //新しいカテゴリ一覧から見て商品数が異なるデータが無いか確認 … … 758 749 } 759 750 751 unset($arrOld); 752 unset($arrNew); 753 760 754 //差分があったIDとその親カテゴリIDのリストを取得する 761 755 $arrTgtCategory_id = array(); … … 763 757 $arrTgtCategory_id[] = $parent_category_id; 764 758 $arrParentID = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 765 $arrTgtCategory_id = array_merge($arrTgtCategory_id, $arrParentID); 766 } 767 768 //重複を取り除く 769 $arrTgtCategory_id = array_unique($arrTgtCategory_id); 759 $arrTgtCategory_id = array_unique(array_merge($arrTgtCategory_id, $arrParentID)); 760 } 761 762 unset($arrDiffCategory_id); 770 763 771 764 //dtb_category_total_count 集計処理開始 772 765 //更新対象カテゴリIDだけ集計しなおす。 773 766 $arrUpdateData = array(); 767 $where_products_class = ''; 768 if (NOSTOCK_HIDDEN) { 769 $where_products_class .= '(stock >= 1 OR stock_unlimited = 1)'; 770 } 771 $from = $objProduct->alldtlSQL($where_products_class); 774 772 foreach ($arrTgtCategory_id as $category_id) { 775 773 $arrval = array(); … … 777 775 if ($tmp_where != '') { 778 776 $sql_where_product_ids = 'product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')'; 779 $arrval = array_merge((array)$tmp_arrval, (array)$tmp_arrval);777 $arrval = $tmp_arrval; 780 778 } else { 781 779 $sql_where_product_ids = '0<>0'; // 一致させない … … 783 781 $where = "($sql_where) AND ($sql_where_product_ids)"; 784 782 785 $where_products_class = ''; 786 if (NOSTOCK_HIDDEN) { 787 $where_products_class .= '(stock >= 1 OR stock_unlimited = 1)'; 788 } 789 790 $from = $objProduct->alldtlSQL($where_products_class); 791 $sql = "SELECT count(*) FROM $from WHERE $where "; 792 $arrUpdateData[ $category_id ] = $objQuery->getOne($sql, $arrval); 793 } 783 $arrUpdateData[$category_id] = $objQuery->count($from, $where, $arrval); 784 } 785 786 unset($arrTgtCategory_id); 787 794 788 // 更新対象だけを更新。 795 789 foreach ($arrUpdateData as $cid => $count) { … … 861 855 $where = "$pid_name IN (" . implode(',', array_fill(0, count($arrPID), '?')) . ")"; 862 856 863 $ret = $objQuery->select($id_name, $table, $where, $arrPID); 864 865 $arrChildren = array(); 866 foreach ($ret as $val) { 867 $arrChildren[] = $val[$id_name]; 868 } 869 870 return $arrChildren; 857 $return = $objQuery->getCol($id_name, $table, $where, $arrPID); 858 859 return $return; 871 860 } 872 861
Note: See TracChangeset
for help on using the changeset viewer.
