source: branches/version-2_5-dev/data/class/helper/SC_Helper_DB.php @ 18859

Revision 18859, 74.4 KB checked in by nanasess, 14 years ago (diff)

ページ間の遷移方法の改善(#783)

  • カート内集計の関数が VIEW に依存しないように修正
  • SC_Helper_DB::sfTotalCart(), SC_Helper_DB::sfTotalConfirm() を SC_CartSession に移動
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * DB関連のヘルパークラス.
26 *
27 * @package Helper
28 * @author LOCKON CO.,LTD.
29 * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $
30 */
31class SC_Helper_DB {
32
33    // {{{ properties
34
35    /** ルートカテゴリ取得フラグ */
36    var $g_root_on;
37
38    /** ルートカテゴリID */
39    var $g_root_id;
40
41    /** 選択中カテゴリ取得フラグ */
42    var $g_category_on;
43
44    /** 選択中カテゴリID */
45    var $g_category_id;
46
47    // }}}
48    // {{{ functions
49
50    /**
51     * データベースのバージョンを所得する.
52     *
53     * @param string $dsn データソース名
54     * @return string データベースのバージョン
55     */
56    function sfGetDBVersion($dsn = "") {
57        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
58        return $dbFactory->sfGetDBVersion($dsn);
59    }
60
61    /**
62     * カラムの存在チェックと作成を行う.
63     *
64     * チェック対象のテーブルに, 該当のカラムが存在するかチェックする.
65     * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う.
66     * カラムの生成も行う場合は, $col_type も必須となる.
67     *
68     * @param string $table_name テーブル名
69     * @param string $column_name カラム名
70     * @param string $col_type カラムのデータ型
71     * @param string $dsn データソース名
72     * @param bool $add カラムの作成も行う場合 true
73     * @return bool カラムが存在する場合とカラムの生成に成功した場合 true,
74     *               テーブルが存在しない場合 false,
75     *               引数 $add == false でカラムが存在しない場合 false
76     */
77    function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
78        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
79        $dsn = $dbFactory->getDSN($dsn);
80
81        $objQuery =& SC_Query::getSingletonInstance($dsn);
82
83        // テーブルが無ければエラー
84        if(!in_array($table_name, $objQuery->listTables())) return false;
85
86        // 正常に接続されている場合
87        if(!$objQuery->isError()) {
88            list($db_type) = split(":", $dsn);
89
90            // カラムリストを取得
91            $columns = $objQuery->listTableFields($table_name);
92
93            if(in_array($col_name, $columns)){
94                return true;
95            }
96        }
97
98        // カラムを追加する
99        if($add){
100            $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
101            return true;
102        }
103        return false;
104    }
105
106    /**
107     * データの存在チェックを行う.
108     *
109     * @param string $table_name テーブル名
110     * @param string $where データを検索する WHERE 句
111     * @param string $dsn データソース名
112     * @param string $sql データの追加を行う場合の SQL文
113     * @param bool $add データの追加も行う場合 true
114     * @return bool データが存在する場合 true, データの追加に成功した場合 true,
115     *               $add == false で, データが存在しない場合 false
116     */
117    function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
118        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
119        $dsn = $dbFactory->getDSN($dsn);
120
121        $objQuery =& SC_Query::getSingletonInstance();
122        $count = $objQuery->count($table_name, $where, $arrval);
123
124        if($count > 0) {
125            $ret = true;
126        } else {
127            $ret = false;
128        }
129        // データを追加する
130        if(!$ret && $add) {
131            $objQuery->exec($sql);
132        }
133        return $ret;
134    }
135
136    /**
137     * 店舗基本情報を取得する.
138     *
139     * @param boolean $force 強制的にDB取得するか
140     * @return array 店舗基本情報の配列
141     */
142    function sf_getBasisData($force = false) {
143        static $data;
144
145        if ($force || !isset($data)) {
146            $objQuery =& SC_Query::getSingletonInstance();
147            $arrRet = $objQuery->select('*', 'dtb_baseinfo');
148
149            if (isset($arrRet[0])) {
150                $data = $arrRet[0];
151            } else {
152                $data = array();
153            }
154        }
155
156        return $data;
157    }
158
159    /* 選択中のアイテムのルートカテゴリIDを取得する */
160    function sfGetRootId() {
161
162        if(!$this->g_root_on)   {
163            $this->g_root_on = true;
164            $objQuery =& SC_Query::getSingletonInstance();
165
166            if (!isset($_GET['product_id'])) $_GET['product_id'] = "";
167            if (!isset($_GET['category_id'])) $_GET['category_id'] = "";
168
169            if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) {
170                // 選択中のカテゴリIDを判定する
171                $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
172                // ROOTカテゴリIDの取得
173                $arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
174                $root_id = isset($arrRet[0]) ? $arrRet[0] : "";
175            } else {
176                // ROOTカテゴリIDをなしに設定する
177                $root_id = "";
178            }
179            $this->g_root_id = $root_id;
180        }
181        return $this->g_root_id;
182    }
183
184    /**
185     * 商品規格情報を取得する.
186     *
187     * TODO SC_Product クラスへ移動
188     *
189     * @param array $arrID 規格ID
190     * @param boolean $includePrivateProducts 非公開商品を含むか
191     * @return array 規格情報の配列
192     */
193    function sfGetProductsClass($arrID, $includePrivateProducts = false) {
194        list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
195
196        if (strlen($classcategory_id1) == 0) {
197            $classcategory_id1 = null;
198        }
199        if (strlen($classcategory_id2) == 0) {
200            $classcategory_id2 = null;
201        }
202
203        // 商品規格取得
204        $objProduct = new SC_Product();
205        $detail = $objProduct->getDetail($product_id);
206        $productsClass = $objProduct->getProductsClassFullByProductId($product_id);
207        foreach ($productsClass as $val) {
208
209            if ($val['classcategory_id1'] == $classcategory_id1
210                && $val['classcategory_id2'] == $classcategory_id2) {
211
212                $detail = array_merge($val, $detail);
213                if (!$includePrivateProducts) {
214                    if ($detail['status'] == 1) {
215                        return $detail;
216                    }
217                }
218                return $detail;
219            }
220        }
221    }
222
223    /**
224     * 支払い方法を取得する.
225     *
226     * @return void
227     */
228    function sfGetPayment() {
229        $objQuery =& SC_Query::getSingletonInstance();
230        // 購入金額が条件額以下の項目を取得
231        $where = "del_flg = 0";
232        $objQuery->setOrder("fix, rank DESC");
233        $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
234        return $arrRet;
235    }
236
237    /**
238     * カート内商品の集計処理を行う.
239     *
240     * 管理機能での利用は想定していないので注意。(非公開商品は除外される。)
241     *
242     * @param LC_Page $objPage ページクラスのインスタンス
243     * @param SC_CartSession $objCartSess カートセッションのインスタンス
244     * @param null $dummy1 互換性確保用(決済モジュール互換のため)
245     * @return LC_Page 集計処理後のページクラスインスタンス
246     *
247     * @deprecated SC_CartSession::checkProducts(),
248     *             SC_CartSession::getAllProductsTotal(),
249     *             SC_CartSession::getAllProductsTax(),
250     *             SC_CartSession::getAllProductsPoint() を使用して下さい
251     */
252    function sfTotalCart(&$objPage, $objCartSess, $dummy1 = null, $key = "") {
253
254        $objPage->tpl_total_pretax[$key] = 0;     // 費用合計(税込み)
255        $objPage->tpl_total_tax[$key] = 0;        // 消費税合計
256        $objPage->tpl_total_point[$key] = 0;      // ポイント合計
257
258        $objProduct = new SC_Product();
259        // カート内情報の取得
260        $arrQuantityInfo_by_product = array();
261        $cnt = 0;
262        foreach ($objCartSess->getCartList() as $arrCart) {
263            // 商品規格情報の取得
264            $arrData = $objProduct->getDetailAndProductsClass($arrCart['id']);
265            $limit = null;
266            // DBに存在する商品
267            if (count($arrData) > 0) {
268
269                // 購入制限数を求める。
270                if ($arrData['stock_unlimited'] != '1' && SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) {
271                    $limit = min($arrData['sale_limit'], $arrData['stock']);
272                } elseif (SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) {
273                    $limit = $arrData['sale_limit'];
274                } elseif ($arrData['stock_unlimited'] != '1') {
275                    $limit = $arrData['stock'];
276                }
277
278                if (!is_null($limit) && $arrCart['quantity'] > $limit) {
279                    if ($limit > 0) {
280                        // カート内商品数を制限に合わせる
281                        $objCartSess->setProductValue($arrCart['id'], 'quantity', $limit);
282                        $quantity = $limit;
283                        $objPage->tpl_message .= "※「" . $arrData['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n";
284                    } else {
285                        // 売り切れ商品をカートから削除する
286                        $objCartSess->delProduct($arrCart['cart_no']);
287                        $objPage->tpl_message .= "※「" . $arrData['name'] . "」は売り切れました。\n";
288                        continue;
289                    }
290                } else {
291                    $quantity = $arrCart['quantity'];
292                }
293
294                // (商品規格単位でなく)商品単位での評価のための準備
295                $product_id = $arrData['product_id'];
296                $arrQuantityInfo_by_product[$product_id]['quantity'] += $quantity;
297                $arrQuantityInfo_by_product[$product_id]['sale_limit'] = $arrData['sale_limit'];
298                $arrQuantityInfo_by_product[$product_id]['name'] = $arrData['name'];
299
300                $objPage->arrProductsClass[$cnt][$key] = $arrData;
301                $objPage->arrProductsClass[$cnt]['quantity'][$key] = $quantity;
302                $objPage->arrProductsClass[$cnt]['cart_no'][$key] = $arrCart['cart_no'];
303                $objPage->arrProductsClass[$cnt]['class_name1'][$key] =
304                    isset($arrData['class_name1'])
305                        ? $arrData['class_name1'] : "";
306
307                $objPage->arrProductsClass[$cnt]['class_name2'][$key] =
308                    isset($arrData['class_name2'])
309                        ? $arrData['class_name2'] : "";
310
311                $objPage->arrProductsClass[$cnt]['classcategory_name1'][$key] = $arrData['name1'];
312
313                $objPage->arrProductsClass[$cnt]['classcategory_name2'][$key] = $arrData['name2'];
314                // 価格の登録
315                $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price02']);
316                $objPage->arrProductsClass[$cnt]['uniq_price'][$key] = $arrData['price02'];
317                // ポイント付与率の登録
318                if (USE_POINT !== false) {
319                    $objCartSess->setProductValue($arrCart['id'], 'point_rate', $arrData['point_rate']);
320                }
321                // 商品ごとの合計金額
322                $objPage->arrProductsClass[$cnt]['total_pretax'][$key] = $objCartSess->getProductTotal($arrCart['id']);
323                // 送料の合計を計算する
324                $objPage->tpl_total_deliv_fee[$key] += ($arrData['deliv_fee'] * $arrCart['quantity']);
325                $cnt++;
326            } else { // DBに商品が見つからない場合、
327                $objPage->tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n";
328                // カート商品の削除
329                $objCartSess->delProduct($arrCart['cart_no']);
330            }
331        }
332
333        foreach ($arrQuantityInfo_by_product as $product_id => $quantityInfo) {
334            if (SC_Utils_Ex::sfIsInt($quantityInfo['sale_limit']) && $quantityInfo['quantity'] > $quantityInfo['sale_limit']) {
335                $objPage->tpl_error = "※「{$quantityInfo['name']}」は数量「{$quantityInfo['sale_limit']}」以下に販売制限しております。一度にこれ以上の購入はできません。\n";
336                // 販売制限に引っかかった商品をマークする
337                foreach (array_keys($objPage->arrProductsClass) as $k) {
338                    $ProductsClass =& $objPage->arrProductsClass[$k];
339                    if ($ProductsClass['product_id'] == $product_id) {
340                        $ProductsClass['error'] = true;
341                    }
342                }
343            }
344        }
345
346        // 全商品合計金額(税込み)
347        $objPage->tpl_total_pretax[$key] = $objCartSess->getAllProductsTotal();
348        // 全商品合計消費税
349        $objPage->tpl_total_tax[$key] = $objCartSess->getAllProductsTax();
350        // 全商品合計ポイント
351        if (USE_POINT !== false) {
352            $objPage->tpl_total_point[$key] = $objCartSess->getAllProductsPoint();
353        }
354
355        return $objPage;
356    }
357
358    /**
359     * 受注一時テーブルへの書き込み処理を行う.
360     *
361     * @param string $uniqid ユニークID
362     * @param array $sqlval SQLの値の配列
363     * @return void
364     */
365    function sfRegistTempOrder($uniqid, $sqlval) {
366        if($uniqid != "") {
367            // 既存データのチェック
368            $objQuery =& SC_Query::getSingletonInstance();
369            $where = "order_temp_id = ?";
370            $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
371            // 既存データがない場合
372            if ($cnt == 0) {
373                // 初回書き込み時に会員の登録済み情報を取り込む
374                $sqlval = $this->sfGetCustomerSqlVal($uniqid, $sqlval);
375                $sqlval['create_date'] = "now()";
376                $objQuery->insert("dtb_order_temp", $sqlval);
377            } else {
378                $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
379            }
380
381            // 受注_Tempテーブルの名称列を更新
382            // ・決済モジュールに対応するため、static メソッドとして扱う
383            SC_Helper_DB_Ex::sfUpdateOrderNameCol($uniqid, true);
384        }
385    }
386
387    /**
388     * 会員情報から SQL文の値を生成する.
389     *
390     * @param string $uniqid ユニークID
391     * @param array $sqlval SQL の値の配列
392     * @return array 会員情報を含んだ SQL の値の配列
393     */
394    function sfGetCustomerSqlVal($uniqid, $sqlval) {
395        $objCustomer = new SC_Customer();
396        // 会員情報登録処理
397        if ($objCustomer->isLoginSuccess(true)) {
398            // 登録データの作成
399            $sqlval['order_temp_id'] = $uniqid;
400            $sqlval['update_date'] = 'Now()';
401            $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
402            $sqlval['order_name01'] = $objCustomer->getValue('name01');
403            $sqlval['order_name02'] = $objCustomer->getValue('name02');
404            $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
405            $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
406            $sqlval['order_sex'] = $objCustomer->getValue('sex');
407            $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
408            $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
409            $sqlval['order_pref'] = $objCustomer->getValue('pref');
410            $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
411            $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
412            $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
413            $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
414            $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
415            if (defined('MOBILE_SITE')) {
416                $email_mobile = $objCustomer->getValue('email_mobile');
417                if (empty($email_mobile)) {
418                    $sqlval['order_email'] = $objCustomer->getValue('email');
419                } else {
420                    $sqlval['order_email'] = $email_mobile;
421                }
422            } else {
423                $sqlval['order_email'] = $objCustomer->getValue('email');
424            }
425            $sqlval['order_job'] = $objCustomer->getValue('job');
426            $sqlval['order_birth'] = $objCustomer->getValue('birth');
427        }
428        return $sqlval;
429    }
430
431    /**
432     * 会員編集登録処理を行う.
433     *
434     * @param array $array パラメータの配列
435     * @param array $arrRegistColumn 登録するカラムの配列
436     * @return void
437     */
438    function sfEditCustomerData($array, $arrRegistColumn) {
439        $objQuery =& SC_Query::getSingletonInstance();
440
441        foreach ($arrRegistColumn as $data) {
442            if ($data["column"] != "password") {
443                if($array[ $data['column'] ] != "") {
444                    $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
445                } else {
446                    $arrRegist[ $data['column'] ] = NULL;
447                }
448            }
449        }
450        if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
451            $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
452        } else {
453            $arrRegist["birth"] = NULL;
454        }
455
456        //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない)
457        if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
458        $arrRegist["update_date"] = "NOW()";
459
460        //-- 編集登録実行
461        $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
462    }
463
464    /**
465     * 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する.
466     *
467     * @param integer $order_id 注文番号
468     * @param integer $use_point 利用ポイント
469     * @param integer $add_point 加算ポイント
470     * @return array 最終ポイントの配列
471     */
472    function sfGetCustomerPoint($order_id, $use_point, $add_point) {
473        $objQuery =& SC_Query::getSingletonInstance();
474        $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
475        $customer_id = $arrRet[0]['customer_id'];
476        if ($customer_id != "" && $customer_id >= 1) {
477            if (USE_POINT !== false) {
478                $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
479                $point = $arrRet[0]['point'];
480                $total_point = $arrRet[0]['point'] - $use_point + $add_point;
481            } else {
482                $total_point = 0;
483                $point = 0;
484            }
485        } else {
486            $total_point = "";
487            $point = "";
488        }
489        return array($point, $total_point);
490    }
491
492    /**
493     * 顧客番号、利用ポイント、加算ポイントから最終ポイントを取得する.
494     *
495     * @param integer $customer_id 顧客番号
496     * @param integer $use_point 利用ポイント
497     * @param integer $add_point 加算ポイント
498     * @return array 最終ポイントの配列
499     */
500    function sfGetCustomerPointFromCid($customer_id, $use_point, $add_point) {
501        $objQuery =& SC_Query::getSingletonInstance();
502        if (USE_POINT !== false) {
503            $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
504            $point = $arrRet[0]['point'];
505            $total_point = $arrRet[0]['point'] - $use_point + $add_point;
506        } else {
507            $total_point = 0;
508            $point = 0;
509        }
510        return array($point, $total_point);
511    }
512    /**
513     * カテゴリツリーの取得を行う.
514     *
515     * @param integer $parent_category_id 親カテゴリID
516     * @param bool $count_check 登録商品数のチェックを行う場合 true
517     * @return array カテゴリツリーの配列
518     */
519    function sfGetCatTree($parent_category_id, $count_check = false) {
520        $objQuery =& SC_Query::getSingletonInstance();
521        $col = "";
522        $col .= " cat.category_id,";
523        $col .= " cat.category_name,";
524        $col .= " cat.parent_category_id,";
525        $col .= " cat.level,";
526        $col .= " cat.rank,";
527        $col .= " cat.creator_id,";
528        $col .= " cat.create_date,";
529        $col .= " cat.update_date,";
530        $col .= " cat.del_flg, ";
531        $col .= " ttl.product_count";
532        $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
533        // 登録商品数のチェック
534        if($count_check) {
535            $where = "del_flg = 0 AND product_count > 0";
536        } else {
537            $where = "del_flg = 0";
538        }
539        $objQuery->setOption("ORDER BY rank DESC");
540        $arrRet = $objQuery->select($col, $from, $where);
541
542        $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
543
544        foreach($arrRet as $key => $array) {
545            foreach($arrParentID as $val) {
546                if($array['category_id'] == $val) {
547                    $arrRet[$key]['display'] = 1;
548                    break;
549                }
550            }
551        }
552
553        return $arrRet;
554    }
555
556    /**
557     * カテゴリツリーの取得を複数カテゴリーで行う.
558     *
559     * @param integer $product_id 商品ID
560     * @param bool $count_check 登録商品数のチェックを行う場合 true
561     * @return array カテゴリツリーの配列
562     */
563    function sfGetMultiCatTree($product_id, $count_check = false) {
564        $objQuery =& SC_Query::getSingletonInstance();
565        $col = "";
566        $col .= " cat.category_id,";
567        $col .= " cat.category_name,";
568        $col .= " cat.parent_category_id,";
569        $col .= " cat.level,";
570        $col .= " cat.rank,";
571        $col .= " cat.creator_id,";
572        $col .= " cat.create_date,";
573        $col .= " cat.update_date,";
574        $col .= " cat.del_flg, ";
575        $col .= " ttl.product_count";
576        $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
577        // 登録商品数のチェック
578        if($count_check) {
579            $where = "del_flg = 0 AND product_count > 0";
580        } else {
581            $where = "del_flg = 0";
582        }
583        $objQuery->setOption("ORDER BY rank DESC");
584        $arrRet = $objQuery->select($col, $from, $where);
585
586        $arrCategory_id = $this->sfGetCategoryId($product_id);
587
588        $arrCatTree = array();
589        foreach ($arrCategory_id as $pkey => $parent_category_id) {
590            $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
591
592            foreach($arrParentID as $pid) {
593                foreach($arrRet as $key => $array) {
594                    if($array['category_id'] == $pid) {
595                        $arrCatTree[$pkey][] = $arrRet[$key];
596                        break;
597                    }
598                }
599            }
600        }
601
602        return $arrCatTree;
603    }
604
605    /**
606     * 親カテゴリーを連結した文字列を取得する.
607     *
608     * @param integer $category_id カテゴリID
609     * @return string 親カテゴリーを連結した文字列
610     */
611    function sfGetCatCombName($category_id){
612        // 商品が属するカテゴリIDを縦に取得
613        $objQuery =& SC_Query::getSingletonInstance();
614        $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
615        $ConbName = "";
616
617        // カテゴリー名称を取得する
618        foreach($arrCatID as $key => $val){
619            $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
620            $arrVal = array($val);
621            $CatName = $objQuery->getOne($sql,$arrVal);
622            $ConbName .= $CatName . ' | ';
623        }
624        // 最後の | をカットする
625        $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2);
626
627        return $ConbName;
628    }
629
630    /**
631     * 指定したカテゴリーIDのカテゴリーを取得する.
632     *
633     * @param integer $category_id カテゴリID
634     * @return array 指定したカテゴリーIDのカテゴリー
635     */
636    function sfGetCat($category_id){
637        $objQuery =& SC_Query::getSingletonInstance();
638
639        // カテゴリーを取得する
640        $arrVal = array($category_id);
641        $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal);
642
643        return $res[0];
644    }
645
646    /**
647     * 指定したカテゴリーIDの大カテゴリーを取得する.
648     *
649     * @param integer $category_id カテゴリID
650     * @return array 指定したカテゴリーIDの大カテゴリー
651     */
652    function sfGetFirstCat($category_id){
653        // 商品が属するカテゴリIDを縦に取得
654        $objQuery =& SC_Query::getSingletonInstance();
655        $arrRet = array();
656        $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
657        $arrRet['id'] = $arrCatID[0];
658
659        // カテゴリー名称を取得する
660        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
661        $arrVal = array($arrRet['id']);
662        $arrRet['name'] = $objQuery->getOne($sql,$arrVal);
663
664        return $arrRet;
665    }
666
667    /**
668     * カテゴリツリーの取得を行う.
669     *
670     * $products_check:true商品登録済みのものだけ取得する
671     *
672     * @param string $addwhere 追加する WHERE 句
673     * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true
674     * @param string $head カテゴリ名のプレフィックス文字列
675     * @return array カテゴリツリーの配列
676     */
677    function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
678        $objQuery =& SC_Query::getSingletonInstance();
679        $where = "del_flg = 0";
680
681        if($addwhere != "") {
682            $where.= " AND $addwhere";
683        }
684
685        $objQuery->setOption("ORDER BY rank DESC");
686
687        if($products_check) {
688            $col = "T1.category_id, category_name, level";
689            $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
690            $where .= " AND product_count > 0";
691        } else {
692            $col = "category_id, category_name, level";
693            $from = "dtb_category";
694        }
695
696        $arrRet = $objQuery->select($col, $from, $where);
697
698        $max = count($arrRet);
699        for($cnt = 0; $cnt < $max; $cnt++) {
700            $id = $arrRet[$cnt]['category_id'];
701            $name = $arrRet[$cnt]['category_name'];
702            $arrList[$id] = str_repeat($head, $arrRet[$cnt]['level']) . $name;
703        }
704        return $arrList;
705    }
706
707    /**
708     * カテゴリーツリーの取得を行う.
709     *
710     * 親カテゴリの Value=0 を対象とする
711     *
712     * @param bool $parent_zero 親カテゴリの Value=0 の場合 true
713     * @return array カテゴリツリーの配列
714     */
715    function sfGetLevelCatList($parent_zero = true) {
716        $objQuery =& SC_Query::getSingletonInstance();
717
718        // カテゴリ名リストを取得
719        $col = "category_id, parent_category_id, category_name";
720        $where = "del_flg = 0";
721        $objQuery->setOption("ORDER BY level");
722        $arrRet = $objQuery->select($col, "dtb_category", $where);
723        $arrCatName = array();
724        foreach ($arrRet as $arrTmp) {
725            $arrCatName[$arrTmp['category_id']] =
726                (($arrTmp['parent_category_id'] > 0)?
727                    $arrCatName[$arrTmp['parent_category_id']] : "")
728                . CATEGORY_HEAD . $arrTmp['category_name'];
729        }
730
731        $col = "category_id, parent_category_id, category_name, level";
732        $where = "del_flg = 0";
733        $objQuery->setOption("ORDER BY rank DESC");
734        $arrRet = $objQuery->select($col, "dtb_category", $where);
735        $max = count($arrRet);
736
737        for($cnt = 0; $cnt < $max; $cnt++) {
738            if($parent_zero) {
739                if($arrRet[$cnt]['level'] == LEVEL_MAX) {
740                    $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
741                } else {
742                    $arrValue[$cnt] = "";
743                }
744            } else {
745                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
746            }
747
748            $arrOutput[$cnt] = $arrCatName[$arrRet[$cnt]['category_id']];
749        }
750
751        return array($arrValue, $arrOutput);
752    }
753
754    /**
755     * 選択中の商品のカテゴリを取得する.
756     *
757     * @param integer $product_id プロダクトID
758     * @param integer $category_id カテゴリID
759     * @return array 選択中の商品のカテゴリIDの配列
760     *
761     */
762    function sfGetCategoryId($product_id, $category_id = 0, $closed = false) {
763        if ($closed) {
764            $status = "";
765        } else {
766            $status = "status = 1";
767        }
768
769        if(!$this->g_category_on) {
770            $this->g_category_on = true;
771            $category_id = (int) $category_id;
772            $product_id = (int) $product_id;
773            if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && $this->sfIsRecord("dtb_category","category_id", $category_id)) {
774                $this->g_category_id = array($category_id);
775            } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) {
776                $objQuery =& SC_Query::getSingletonInstance();
777                $where = "product_id = ?";
778                $category_id = $objQuery->getCol("dtb_product_categories", "category_id", "product_id = ?", array($product_id));
779                $this->g_category_id = $category_id;
780            } else {
781                // 不正な場合は、空の配列を返す。
782                $this->g_category_id = array();
783            }
784        }
785        return $this->g_category_id;
786    }
787
788    /**
789     * 商品をカテゴリの先頭に追加する.
790     *
791     * @param integer $category_id カテゴリID
792     * @param integer $product_id プロダクトID
793     * @return void
794     */
795    function addProductBeforCategories($category_id, $product_id) {
796
797        $sqlval = array("category_id" => $category_id,
798                        "product_id" => $product_id);
799
800        $objQuery =& SC_Query::getSingletonInstance();
801
802        // 現在の商品カテゴリを取得
803        $arrCat = $objQuery->select("product_id, category_id, rank",
804                                    "dtb_product_categories",
805                                    "category_id = ?",
806                                    array($category_id));
807
808        $max = "0";
809        foreach ($arrCat as $val) {
810            // 同一商品が存在する場合は登録しない
811            if ($val["product_id"] == $product_id) {
812                return;
813            }
814            // 最上位ランクを取得
815            $max = ($max < $val["rank"]) ? $val["rank"] : $max;
816        }
817        $sqlval["rank"] = $max + 1;
818        $objQuery->insert("dtb_product_categories", $sqlval);
819    }
820
821    /**
822     * 商品をカテゴリの末尾に追加する.
823     *
824     * @param integer $category_id カテゴリID
825     * @param integer $product_id プロダクトID
826     * @return void
827     */
828    function addProductAfterCategories($category_id, $product_id) {
829        $sqlval = array("category_id" => $category_id,
830                        "product_id" => $product_id);
831
832        $objQuery =& SC_Query::getSingletonInstance();
833
834        // 現在の商品カテゴリを取得
835        $arrCat = $objQuery->select("product_id, category_id, rank",
836                                    "dtb_product_categories",
837                                    "category_id = ?",
838                                    array($category_id));
839
840        $min = 0;
841        foreach ($arrCat as $val) {
842            // 同一商品が存在する場合は登録しない
843            if ($val["product_id"] == $product_id) {
844                return;
845            }
846            // 最下位ランクを取得
847            $min = ($min < $val["rank"]) ? $val["rank"] : $min;
848        }
849        $sqlval["rank"] = $min;
850        $objQuery->insert("dtb_product_categories", $sqlval);
851    }
852
853    /**
854     * 商品をカテゴリから削除する.
855     *
856     * @param integer $category_id カテゴリID
857     * @param integer $product_id プロダクトID
858     * @return void
859     */
860    function removeProductByCategories($category_id, $product_id) {
861        $sqlval = array("category_id" => $category_id,
862                        "product_id" => $product_id);
863        $objQuery =& SC_Query::getSingletonInstance();
864        $objQuery->delete("dtb_product_categories",
865                          "category_id = ? AND product_id = ?", $sqlval);
866    }
867
868    /**
869     * 商品カテゴリを更新する.
870     *
871     * @param array $arrCategory_id 登録するカテゴリIDの配列
872     * @param integer $product_id プロダクトID
873     * @return void
874     */
875    function updateProductCategories($arrCategory_id, $product_id) {
876        $objQuery =& SC_Query::getSingletonInstance();
877
878        // 現在のカテゴリ情報を取得
879        $arrCurrentCat = $objQuery->select("product_id, category_id, rank",
880                                           "dtb_product_categories",
881                                           "product_id = ?",
882                                           array($product_id));
883
884        // 登録するカテゴリ情報と比較
885        foreach ($arrCurrentCat as $val) {
886
887            // 登録しないカテゴリを削除
888            if (!in_array($val["category_id"], $arrCategory_id)) {
889                $this->removeProductByCategories($val["category_id"], $product_id);
890            }
891        }
892
893        // カテゴリを登録
894        foreach ($arrCategory_id as $category_id) {
895            $this->addProductBeforCategories($category_id, $product_id);
896        }
897    }
898
899    /**
900     * カテゴリ数の登録を行う.
901     *
902     * @param SC_Query $objQuery SC_Query インスタンス
903     * @return void
904     */
905    function sfCategory_Count($objQuery){
906
907        //テーブル内容の削除
908        $objQuery->query("DELETE FROM dtb_category_count");
909        $objQuery->query("DELETE FROM dtb_category_total_count");
910
911        $sql_where .= 'alldtl.del_flg = 0 AND alldtl.status = 1';
912        // 在庫無し商品の非表示
913        if (NOSTOCK_HIDDEN === true) {
914            $sql_where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)';
915        }
916
917        //子カテゴリ内の商品数を集計する
918
919        // カテゴリ情報を取得
920        $arrCat = $objQuery->select('category_id', 'dtb_category');
921
922        $objProduct = new SC_Product();
923
924        foreach ($arrCat as $row) {
925            $category_id = $row['category_id'];
926            $arrval = array();
927
928            $arrval[] = $category_id;
929
930            list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id);
931            if ($tmp_where != "") {
932                $sql_where_product_ids = "product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
933                $arrval = array_merge((array)$arrval, (array)$tmp_arrval, (array)$tmp_arrval);
934            } else {
935                $sql_where_product_ids = '0<>0'; // 一致させない
936            }
937            $where = "($sql_where) AND ($sql_where_product_ids)";
938
939            $from = $objProduct->alldtlSQL($sql_where_product_ids);
940            $sql = <<< __EOS__
941                INSERT INTO dtb_category_total_count (category_id, product_count, create_date)
942                SELECT
943                    ?
944                    ,count(*)
945                    ,now()
946                FROM $from
947               WHERE $where
948__EOS__;
949
950            $objQuery->query($sql, $arrval);
951        }
952    }
953
954    /**
955     * 子IDの配列を返す.
956     *
957     * @param string $table テーブル名
958     * @param string $pid_name 親ID名
959     * @param string $id_name ID名
960     * @param integer $id ID
961     * @param array 子ID の配列
962     */
963    function sfGetChildsID($table, $pid_name, $id_name, $id) {
964        $arrRet = $this->sfGetChildrenArray($table, $pid_name, $id_name, $id);
965        return $arrRet;
966    }
967
968    /**
969     * 階層構造のテーブルから子ID配列を取得する.
970     *
971     * @param string $table テーブル名
972     * @param string $pid_name 親ID名
973     * @param string $id_name ID名
974     * @param integer $id ID番号
975     * @return array 子IDの配列
976     */
977    function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
978        $objQuery =& SC_Query::getSingletonInstance();
979        $col = $pid_name . "," . $id_name;
980        $arrData = $objQuery->select($col, $table);
981
982        $arrPID = array();
983        $arrPID[] = $id;
984        $arrChildren = array();
985        $arrChildren[] = $id;
986
987        $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
988
989        while(count($arrRet) > 0) {
990            $arrChildren = array_merge($arrChildren, $arrRet);
991            $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
992        }
993
994        return $arrChildren;
995    }
996
997    /**
998     * 親ID直下の子IDをすべて取得する.
999     *
1000     * @param array $arrData 親カテゴリの配列
1001     * @param string $pid_name 親ID名
1002     * @param string $id_name ID名
1003     * @param array $arrPID 親IDの配列
1004     * @return array 子IDの配列
1005     */
1006    function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
1007        $arrChildren = array();
1008        $max = count($arrData);
1009
1010        for($i = 0; $i < $max; $i++) {
1011            foreach($arrPID as $val) {
1012                if($arrData[$i][$pid_name] == $val) {
1013                    $arrChildren[] = $arrData[$i][$id_name];
1014                }
1015            }
1016        }
1017        return $arrChildren;
1018    }
1019
1020    /**
1021     * 所属するすべての階層の親IDを配列で返す.
1022     *
1023     * @param SC_Query $objQuery SC_Query インスタンス
1024     * @param string $table テーブル名
1025     * @param string $pid_name 親ID名
1026     * @param string $id_name ID名
1027     * @param integer $id ID
1028     * @return array 親IDの配列
1029     */
1030    function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
1031        $arrRet = $this->sfGetParentsArray($table, $pid_name, $id_name, $id);
1032        // 配列の先頭1つを削除する。
1033        array_shift($arrRet);
1034        return $arrRet;
1035    }
1036
1037    /**
1038     * 階層構造のテーブルから親ID配列を取得する.
1039     *
1040     * @param string $table テーブル名
1041     * @param string $pid_name 親ID名
1042     * @param string $id_name ID名
1043     * @param integer $id ID
1044     * @return array 親IDの配列
1045     */
1046    function sfGetParentsArray($table, $pid_name, $id_name, $id) {
1047        $objQuery =& SC_Query::getSingletonInstance();
1048        $col = $pid_name . "," . $id_name;
1049        $arrData = $objQuery->select($col, $table);
1050
1051        $arrParents = array();
1052        $arrParents[] = $id;
1053        $child = $id;
1054
1055        $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
1056
1057        while($ret != "") {
1058            $arrParents[] = $ret;
1059            $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
1060        }
1061
1062        $arrParents = array_reverse($arrParents);
1063
1064        return $arrParents;
1065    }
1066
1067    /**
1068     * カテゴリから商品を検索する場合のWHERE文と値を返す.
1069     *
1070     * @param integer $category_id カテゴリID
1071     * @return array 商品を検索する場合の配列
1072     */
1073    function sfGetCatWhere($category_id) {
1074        // 子カテゴリIDの取得
1075        $arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
1076        $tmp_where = "";
1077        foreach ($arrRet as $val) {
1078            if($tmp_where == "") {
1079                $tmp_where.= "category_id IN ( ?";
1080            } else {
1081                $tmp_where.= ",? ";
1082            }
1083            $arrval[] = $val;
1084        }
1085        $tmp_where.= " ) ";
1086        return array($tmp_where, $arrval);
1087    }
1088
1089    /**
1090     * 受注一時テーブルから情報を取得する.
1091     *
1092     * @param integer $order_temp_id 受注一時ID
1093     * @return array 受注一時情報の配列
1094     */
1095    function sfGetOrderTemp($order_temp_id) {
1096        $objQuery =& SC_Query::getSingletonInstance();
1097        $where = "order_temp_id = ?";
1098        $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
1099        return $arrRet[0];
1100    }
1101
1102    /**
1103     * SELECTボックス用リストを作成する.
1104     *
1105     * @param string $table テーブル名
1106     * @param string $keyname プライマリーキーのカラム名
1107     * @param string $valname データ内容のカラム名
1108     * @return array SELECT ボックス用リストの配列
1109     */
1110    function sfGetIDValueList($table, $keyname, $valname) {
1111        $objQuery =& SC_Query::getSingletonInstance();
1112        $col = "$keyname, $valname";
1113        $objQuery->setWhere("del_flg = 0");
1114        $objQuery->setOrder("rank DESC");
1115        $arrList = $objQuery->select($col, $table);
1116        $count = count($arrList);
1117        for($cnt = 0; $cnt < $count; $cnt++) {
1118            $key = $arrList[$cnt][$keyname];
1119            $val = $arrList[$cnt][$valname];
1120            $arrRet[$key] = $val;
1121        }
1122        return $arrRet;
1123    }
1124
1125    /**
1126     * ランキングを上げる.
1127     *
1128     * @param string $table テーブル名
1129     * @param string $colname カラム名
1130     * @param string|integer $id テーブルのキー
1131     * @param string $andwhere SQL の AND 条件である WHERE 句
1132     * @return void
1133     */
1134    function sfRankUp($table, $colname, $id, $andwhere = "") {
1135        $objQuery =& SC_Query::getSingletonInstance();
1136        $objQuery->begin();
1137        $where = "$colname = ?";
1138        if($andwhere != "") {
1139            $where.= " AND $andwhere";
1140        }
1141        // 対象項目のランクを取得
1142        $rank = $objQuery->get($table, "rank", $where, array($id));
1143        // ランクの最大値を取得
1144        $maxrank = $objQuery->max($table, "rank", $andwhere);
1145        // ランクが最大値よりも小さい場合に実行する。
1146        if($rank < $maxrank) {
1147            // ランクが一つ上のIDを取得する。
1148            $where = "rank = ?";
1149            if($andwhere != "") {
1150                $where.= " AND $andwhere";
1151            }
1152            $uprank = $rank + 1;
1153            $up_id = $objQuery->get($table, $colname, $where, array($uprank));
1154            // ランク入れ替えの実行
1155            $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";
1156            if($andwhere != "") {
1157                $sqlup.= " AND $andwhere";
1158            }
1159            $objQuery->exec($sqlup, array($rank + 1, $id));
1160            $objQuery->exec($sqlup, array($rank, $up_id));
1161        }
1162        $objQuery->commit();
1163    }
1164
1165    /**
1166     * ランキングを下げる.
1167     *
1168     * @param string $table テーブル名
1169     * @param string $colname カラム名
1170     * @param string|integer $id テーブルのキー
1171     * @param string $andwhere SQL の AND 条件である WHERE 句
1172     * @return void
1173     */
1174    function sfRankDown($table, $colname, $id, $andwhere = "") {
1175        $objQuery =& SC_Query::getSingletonInstance();
1176        $objQuery->begin();
1177        $where = "$colname = ?";
1178        if($andwhere != "") {
1179            $where.= " AND $andwhere";
1180        }
1181        // 対象項目のランクを取得
1182        $rank = $objQuery->get($table, "rank", $where, array($id));
1183
1184        // ランクが1(最小値)よりも大きい場合に実行する。
1185        if($rank > 1) {
1186            // ランクが一つ下のIDを取得する。
1187            $where = "rank = ?";
1188            if($andwhere != "") {
1189                $where.= " AND $andwhere";
1190            }
1191            $downrank = $rank - 1;
1192            $down_id = $objQuery->get($table, $colname, $where, array($downrank));
1193            // ランク入れ替えの実行
1194            $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?";
1195            if($andwhere != "") {
1196                $sqlup.= " AND $andwhere";
1197            }
1198            $objQuery->exec($sqlup, array($rank - 1, $id));
1199            $objQuery->exec($sqlup, array($rank, $down_id));
1200        }
1201        $objQuery->commit();
1202    }
1203
1204    /**
1205     * 指定順位へ移動する.
1206     *
1207     * @param string $tableName テーブル名
1208     * @param string $keyIdColumn キーを保持するカラム名
1209     * @param string|integer $keyId キーの値
1210     * @param integer $pos 指定順位
1211     * @param string $where SQL の AND 条件である WHERE 句
1212     * @return void
1213     */
1214    function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
1215        $objQuery =& SC_Query::getSingletonInstance();
1216        $objQuery->begin();
1217
1218        // 自身のランクを取得する
1219        if($where != "") {
1220            $getWhere = "$keyIdColumn = ? AND " . $where;
1221        } else {
1222            $getWhere = "$keyIdColumn = ?";
1223        }
1224        $rank = $objQuery->get($tableName, "rank", $getWhere, array($keyId));
1225
1226        $max = $objQuery->max($tableName, "rank", $where);
1227
1228        // 値の調整(逆順)
1229        if($pos > $max) {
1230            $position = 1;
1231        } else if($pos < 1) {
1232            $position = $max;
1233        } else {
1234            $position = $max - $pos + 1;
1235        }
1236
1237        //入れ替え先の順位が入れ換え元の順位より大きい場合
1238        if( $position > $rank ) $term = "rank - 1";
1239
1240        //入れ替え先の順位が入れ換え元の順位より小さい場合
1241        if( $position < $rank ) $term = "rank + 1";
1242
1243        // XXX 入れ替え先の順位が入れ替え元の順位と同じ場合
1244        if (!isset($term)) $term = "rank";
1245
1246        // 指定した順位の商品から移動させる商品までのrankを1つずらす
1247        $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?";
1248        if($where != "") {
1249            $sql.= " AND $where";
1250        }
1251
1252        if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));
1253        if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));
1254
1255        // 指定した順位へrankを書き換える。
1256        $sql  = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? ";
1257        if($where != "") {
1258            $sql.= " AND $where";
1259        }
1260
1261        $objQuery->exec( $sql, array( $position, $keyId ) );
1262        $objQuery->commit();
1263    }
1264
1265    /**
1266     * ランクを含むレコードを削除する.
1267     *
1268     * レコードごと削除する場合は、$deleteをtrueにする
1269     *
1270     * @param string $table テーブル名
1271     * @param string $colname カラム名
1272     * @param string|integer $id テーブルのキー
1273     * @param string $andwhere SQL の AND 条件である WHERE 句
1274     * @param bool $delete レコードごと削除する場合 true,
1275     *                     レコードごと削除しない場合 false
1276     * @return void
1277     */
1278    function sfDeleteRankRecord($table, $colname, $id, $andwhere = "",
1279                                $delete = false) {
1280        $objQuery =& SC_Query::getSingletonInstance();
1281        $objQuery->begin();
1282        // 削除レコードのランクを取得する。
1283        $where = "$colname = ?";
1284        if($andwhere != "") {
1285            $where.= " AND $andwhere";
1286        }
1287        $rank = $objQuery->get($table, "rank", $where, array($id));
1288
1289        if(!$delete) {
1290            // ランクを最下位にする、DELフラグON
1291            $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 ";
1292            $sqlup.= "WHERE $colname = ?";
1293            // UPDATEの実行
1294            $objQuery->exec($sqlup, array($id));
1295        } else {
1296            $objQuery->delete($table, "$colname = ?", array($id));
1297        }
1298
1299        // 追加レコードのランクより上のレコードを一つずらす。
1300        $where = "rank > ?";
1301        if($andwhere != "") {
1302            $where.= " AND $andwhere";
1303        }
1304        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1305        $objQuery->exec($sqlup, array($rank));
1306        $objQuery->commit();
1307    }
1308
1309    /**
1310     * 親IDの配列を元に特定のカラムを取得する.
1311     *
1312     * @param SC_Query $objQuery SC_Query インスタンス
1313     * @param string $table テーブル名
1314     * @param string $id_name ID名
1315     * @param string $col_name カラム名
1316     * @param array $arrId IDの配列
1317     * @return array 特定のカラムの配列
1318     */
1319    function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
1320        $col = $col_name;
1321        $len = count($arrId);
1322        $where = "";
1323
1324        for($cnt = 0; $cnt < $len; $cnt++) {
1325            if($where == "") {
1326                $where = "$id_name = ?";
1327            } else {
1328                $where.= " OR $id_name = ?";
1329            }
1330        }
1331
1332        $objQuery->setOrder("level");
1333        $arrRet = $objQuery->select($col, $table, $where, $arrId);
1334        return $arrRet;
1335    }
1336
1337    /**
1338     * カテゴリ変更時の移動処理を行う.
1339     *
1340     * @param SC_Query $objQuery SC_Query インスタンス
1341     * @param string $table テーブル名
1342     * @param string $id_name ID名
1343     * @param string $cat_name カテゴリ名
1344     * @param integer $old_catid 旧カテゴリID
1345     * @param integer $new_catid 新カテゴリID
1346     * @param integer $id ID
1347     * @return void
1348     */
1349    function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
1350        if ($old_catid == $new_catid) {
1351            return;
1352        }
1353        // 旧カテゴリでのランク削除処理
1354        // 移動レコードのランクを取得する。
1355        $where = "$id_name = ?";
1356        $rank = $objQuery->get($table, "rank", $where, array($id));
1357        // 削除レコードのランクより上のレコードを一つ下にずらす。
1358        $where = "rank > ? AND $cat_name = ?";
1359        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1360        $objQuery->exec($sqlup, array($rank, $old_catid));
1361        // 新カテゴリでの登録処理
1362        // 新カテゴリの最大ランクを取得する。
1363        $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
1364        $where = "$id_name = ?";
1365        $sqlup = "UPDATE $table SET rank = ? WHERE $where";
1366        $objQuery->exec($sqlup, array($max_rank, $id));
1367    }
1368
1369    /**
1370     * お届け時間を取得する.
1371     *
1372     * @param integer $payment_id 支払い方法ID
1373     * @return array お届け時間の配列
1374     */
1375    function sfGetDelivTime($payment_id = "") {
1376        $objQuery =& SC_Query::getSingletonInstance();
1377
1378        $deliv_id = "";
1379        $arrRet = array();
1380
1381        if($payment_id != "") {
1382            $where = "del_flg = 0 AND payment_id = ?";
1383            $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1384            $deliv_id = $arrRet[0]['deliv_id'];
1385        }
1386
1387        if($deliv_id != "") {
1388            $objQuery->setOrder("time_id");
1389            $where = "deliv_id = ?";
1390            $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
1391        }
1392
1393        return $arrRet;
1394    }
1395
1396    /**
1397     * 都道府県、支払い方法から配送料金を取得する.
1398     *
1399     * @param array $arrData 各種情報
1400     * @return string 指定の都道府県, 支払い方法の配送料金
1401     */
1402    function sfGetDelivFee($arrData) {
1403        $pref = $arrData['deliv_pref'];
1404        $payment_id = isset($arrData['payment_id']) ? $arrData['payment_id'] : "";
1405
1406        $objQuery =& SC_Query::getSingletonInstance();
1407
1408        $deliv_id = "";
1409
1410        // 支払い方法が指定されている場合は、対応した配送業者を取得する
1411        if($payment_id != "") {
1412            $where = "del_flg = 0 AND payment_id = ?";
1413            $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1414            $deliv_id = $arrRet[0]['deliv_id'];
1415        // 支払い方法が指定されていない場合は、先頭の配送業者を取得する
1416        } else {
1417            $where = "del_flg = 0";
1418            $objQuery->setOrder("rank DESC");
1419            $objQuery->setLimitOffset(1);
1420            $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
1421            $deliv_id = $arrRet[0]['deliv_id'];
1422        }
1423
1424        // 配送業者から配送料を取得
1425        if($deliv_id != "") {
1426
1427            // 都道府県が指定されていない場合は、東京都の番号を指定しておく
1428            if($pref == "") {
1429                $pref = 13;
1430            }
1431
1432            $objQuery =& SC_Query::getSingletonInstance();
1433            $where = "deliv_id = ? AND pref = ?";
1434            $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
1435        }
1436        return $arrRet[0]['fee'];
1437    }
1438
1439    /**
1440     * 集計情報を元に最終計算を行う.
1441     *
1442     * @param array $arrData 各種情報
1443     * @param LC_Page $objPage LC_Page インスタンス
1444     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
1445     * @param null $dummy1 互換性確保用(決済モジュール互換のため)
1446     * @param SC_Customer $objCustomer SC_Customer インスタンス
1447     * @return array 最終計算後の配列
1448     * @deprecated SC_CartSession::calculate() を使用して下さい
1449     */
1450    function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $dummy1 = null, $objCustomer = "", $key = "") {
1451        // 店舗基本情報を取得する
1452        $arrInfo = SC_Helper_DB_Ex::sf_getBasisData();
1453
1454        // 未定義変数を定義
1455        if (!isset($arrData['deliv_pref'])) $arrData['deliv_pref'] = "";
1456        if (!isset($arrData['payment_id'])) $arrData['payment_id'] = "";
1457        if (!isset($arrData['charge'])) $arrData['charge'] = "";
1458        if (!isset($arrData['use_point'])) $arrData['use_point'] = "";
1459        if (!isset($arrData['add_point'])) $arrData['add_point'] = 0;
1460
1461        // 税金の取得
1462        $arrData['tax'] = $objPage->tpl_total_tax[$key];
1463        // 小計の取得
1464        $arrData['subtotal'] = $objPage->tpl_total_pretax[$key];
1465
1466        // 合計送料の取得
1467        $arrData['deliv_fee'] = 0;
1468
1469        // 商品ごとの送料が有効の場合
1470        if (OPTION_PRODUCT_DELIV_FEE == 1) {
1471            // 全商品の合計送料を加算する
1472            $this->lfAddAllProductsDelivFee($arrData, $objPage, $objCartSess);
1473        }
1474
1475        // 配送業者の送料が有効の場合
1476        if (OPTION_DELIV_FEE == 1) {
1477            // 都道府県、支払い方法から配送料金を加算する
1478            // FIXME ここでしか使ってない
1479            $this->lfAddDelivFee($arrData);
1480        }
1481
1482        // 送料無料の購入数が設定されている場合
1483        if (DELIV_FREE_AMOUNT > 0) {
1484            // 商品の合計数量
1485            $total_quantity = $objCartSess->getTotalQuantity(true);
1486
1487            if($total_quantity >= DELIV_FREE_AMOUNT) {
1488                $arrData['deliv_fee'] = 0;
1489            }
1490        }
1491
1492        // ダウンロード商品のみの場合は送料無料
1493        if($this->chkCartDown($objCartSess)==2){
1494            $arrData['deliv_fee'] = 0;
1495        }
1496
1497        // 送料無料条件が設定されている場合
1498        if($arrInfo['free_rule'] > 0) {
1499            // 小計が無料条件を超えている場合
1500            if($arrData['subtotal'] >= $arrInfo['free_rule']) {
1501                $arrData['deliv_fee'] = 0;
1502            }
1503        }
1504
1505        // 合計の計算
1506        $arrData['total'] = $objPage->tpl_total_pretax[$key]; // 商品合計
1507        $arrData['total']+= $arrData['deliv_fee'];      // 送料
1508        $arrData['total']+= $arrData['charge'];         // 手数料
1509        // お支払い合計
1510        $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
1511        // 加算ポイントの計算
1512        if (USE_POINT !== false) {
1513            $arrData['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($objPage->tpl_total_point[$key], $arrData['use_point']);
1514
1515            if($objCustomer != "") {
1516                // 誕生日月であった場合
1517                if($objCustomer->isBirthMonth()) {
1518                    $arrData['birth_point'] = BIRTH_MONTH_POINT;
1519                    $arrData['add_point'] += $arrData['birth_point'];
1520                }
1521            }
1522        }
1523
1524        if($arrData['add_point'] < 0) {
1525            $arrData['add_point'] = 0;
1526        }
1527        return $arrData;
1528    }
1529
1530    /**
1531     * レコードの存在チェックを行う.
1532     *
1533     * @param string $table テーブル名
1534     * @param string $col カラム名
1535     * @param array $arrval 要素の配列
1536     * @param array $addwhere SQL の AND 条件である WHERE 句
1537     * @return bool レコードが存在する場合 true
1538     */
1539    function sfIsRecord($table, $col, $arrval, $addwhere = "") {
1540        $objQuery =& SC_Query::getSingletonInstance();
1541        $arrCol = split("[, ]", $col);
1542
1543        $where = "del_flg = 0";
1544
1545        if($addwhere != "") {
1546            $where.= " AND $addwhere";
1547        }
1548
1549        foreach($arrCol as $val) {
1550            if($val != "") {
1551                if($where == "") {
1552                    $where = "$val = ?";
1553                } else {
1554                    $where.= " AND $val = ?";
1555                }
1556            }
1557        }
1558        $ret = $objQuery->get($table, $col, $where, $arrval);
1559
1560        if($ret != "") {
1561            return true;
1562        }
1563        return false;
1564    }
1565
1566    /**
1567     * メーカー商品数数の登録を行う.
1568     *
1569     * @param SC_Query $objQuery SC_Query インスタンス
1570     * @return void
1571     */
1572    function sfMaker_Count($objQuery){
1573        $sql = "";
1574
1575        //テーブル内容の削除
1576        $objQuery->query("DELETE FROM dtb_maker_count");
1577
1578        //各メーカーの商品数を数えて格納
1579        $sql = " INSERT INTO dtb_maker_count(maker_id, product_count, create_date) ";
1580        $sql .= " SELECT T1.maker_id, count(T2.maker_id), now() ";
1581        $sql .= " FROM dtb_maker AS T1 LEFT JOIN dtb_products AS T2";
1582        $sql .= " ON T1.maker_id = T2.maker_id ";
1583        $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";
1584        $sql .= " GROUP BY T1.maker_id, T2.maker_id ";
1585        $objQuery->query($sql);
1586    }
1587
1588    /**
1589     * 選択中の商品のメーカーを取得する.
1590     *
1591     * @param integer $product_id プロダクトID
1592     * @param integer $maker_id メーカーID
1593     * @return array 選択中の商品のメーカーIDの配列
1594     *
1595     */
1596    function sfGetMakerId($product_id, $maker_id = 0, $closed = false) {
1597        if ($closed) {
1598            $status = "";
1599        } else {
1600            $status = "status = 1";
1601        }
1602
1603        if (!$this->g_maker_on) {
1604            $this->g_maker_on = true;
1605            $maker_id = (int) $maker_id;
1606            $product_id = (int) $product_id;
1607            if (SC_Utils_Ex::sfIsInt($maker_id) && $maker_id != 0 && $this->sfIsRecord("dtb_maker","maker_id", $maker_id)) {
1608                $this->g_maker_id = array($maker_id);
1609            } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) {
1610                $objQuery =& SC_Query::getSingletonInstance();
1611                $where = "product_id = ?";
1612                $maker_id = $objQuery->getCol("dtb_products", "maker_id", "product_id = ?", array($product_id));
1613                $this->g_maker_id = $maker_id;
1614            } else {
1615                // 不正な場合は、空の配列を返す。
1616                $this->g_maker_id = array();
1617            }
1618        }
1619        return $this->g_maker_id;
1620    }
1621
1622    /**
1623     * メーカーの取得を行う.
1624     *
1625     * $products_check:true商品登録済みのものだけ取得する
1626     *
1627     * @param string $addwhere 追加する WHERE 句
1628     * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true
1629     * @return array カテゴリツリーの配列
1630     */
1631    function sfGetMakerList($addwhere = "", $products_check = false) {
1632        $objQuery =& SC_Query::getSingletonInstance();
1633        $where = "del_flg = 0";
1634
1635        if($addwhere != "") {
1636            $where.= " AND $addwhere";
1637        }
1638
1639        $objQuery->setOption("ORDER BY rank DESC");
1640
1641        if($products_check) {
1642            $col = "T1.maker_id, name";
1643            $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id";
1644            $where .= " AND product_count > 0";
1645        } else {
1646            $col = "maker_id, name";
1647            $from = "dtb_maker";
1648        }
1649
1650        $arrRet = $objQuery->select($col, $from, $where);
1651
1652        $max = count($arrRet);
1653        for($cnt = 0; $cnt < $max; $cnt++) {
1654            $id = $arrRet[$cnt]['maker_id'];
1655            $name = $arrRet[$cnt]['name'];
1656            $arrList[$id].= $name;
1657        }
1658        return $arrList;
1659    }
1660
1661    /**
1662     * 全商品の合計送料を加算する
1663     */
1664    function lfAddAllProductsDelivFee(&$arrData, &$objPage, &$objCartSess) {
1665        $arrData['deliv_fee'] += $this->lfCalcAllProductsDelivFee($arrData, $objCartSess);
1666    }
1667
1668    /**
1669     * 全商品の合計送料を計算する
1670     */
1671    function lfCalcAllProductsDelivFee(&$arrData, &$objCartSess) {
1672        $objQuery =& SC_Query::getSingletonInstance();
1673        $deliv_fee_total = 0;
1674        $max = $objCartSess->getMax();
1675        for ($i = 0; $i <= $max; $i++) {
1676            // 商品送料
1677            $deliv_fee = $objQuery->getOne('SELECT deliv_fee FROM dtb_products WHERE product_id = ?', array($_SESSION[$objCartSess->key][$i]['id'][0]));
1678            // 数量
1679            $quantity = $_SESSION[$objCartSess->key][$i]['quantity'];
1680            // 累積
1681            $deliv_fee_total += $deliv_fee * $quantity;
1682        }
1683        return $deliv_fee_total;
1684    }
1685
1686    /**
1687     * 都道府県、支払い方法から配送料金を加算する.
1688     *
1689     * @param array $arrData 各種情報
1690     */
1691    function lfAddDelivFee(&$arrData) {
1692        $arrData['deliv_fee'] += $this->sfGetDelivFee($arrData);
1693    }
1694
1695    /**
1696     * 受注の名称列を更新する
1697     *
1698     * @param integer $order_id 更新対象の注文番号
1699     * @param boolean $temp_table 更新対象は「受注_Temp」か
1700     * @static
1701     */
1702    function sfUpdateOrderNameCol($order_id, $temp_table = false) {
1703        $objQuery =& SC_Query::getSingletonInstance();
1704
1705        if ($temp_table) {
1706            $tgt_table = 'dtb_order_temp';
1707            $sql_where = 'WHERE order_temp_id = ?';
1708        } else {
1709            $tgt_table = 'dtb_order';
1710            $sql_where = 'WHERE order_id = ?';
1711        }
1712
1713        $sql = <<< __EOS__
1714            UPDATE
1715                {$tgt_table}
1716            SET
1717                 payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = {$tgt_table}.payment_id)
1718                ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = {$tgt_table}.deliv_time_id AND deliv_id = {$tgt_table}.deliv_id)
1719            $sql_where
1720__EOS__;
1721
1722        $objQuery->query($sql, array($order_id));
1723    }
1724
1725    /**
1726     * 店舗基本情報に基づいて税金額を返す
1727     *
1728     * @param integer $price 計算対象の金額
1729     * @return integer 税金額
1730     */
1731    function sfTax($price) {
1732        // 店舗基本情報を取得
1733        $CONF = SC_Helper_DB_Ex::sf_getBasisData();
1734
1735        return SC_Utils_Ex::sfTax($price, $CONF['tax'], $CONF['tax_rule']);
1736    }
1737
1738    /**
1739     * 店舗基本情報に基づいて税金付与した金額を返す
1740     *
1741     * @param integer $price 計算対象の金額
1742     * @return integer 税金付与した金額
1743     */
1744    function sfPreTax($price, $tax = null, $tax_rule = null) {
1745        // 店舗基本情報を取得
1746        $CONF = SC_Helper_DB_Ex::sf_getBasisData();
1747
1748        return SC_Utils_Ex::sfPreTax($price, $CONF['tax'], $CONF['tax_rule']);
1749    }
1750
1751    /**
1752     * 店舗基本情報に基づいて加算ポイントを返す
1753     *
1754     * @param integer $totalpoint
1755     * @param integer $use_point
1756     * @return integer 加算ポイント
1757     */
1758    function sfGetAddPoint($totalpoint, $use_point) {
1759        // 店舗基本情報を取得
1760        $CONF = SC_Helper_DB_Ex::sf_getBasisData();
1761
1762        return SC_Utils_Ex::sfGetAddPoint($totalpoint, $use_point, $CONF['point_rate']);
1763    }
1764
1765    /**
1766     * 受注.対応状況の更新
1767     *
1768     * ・必ず呼び出し元でトランザクションブロックを開いておくこと。
1769     *
1770     * @param integer $orderId 注文番号
1771     * @param integer|null $newStatus 対応状況 (null=変更無し)
1772     * @param integer|null $newAddPoint 加算ポイント (null=変更無し)
1773     * @param integer|null $newUsePoint 使用ポイント (null=変更無し)
1774     * @return void
1775     */
1776    function sfUpdateOrderStatus($orderId, $newStatus = null, $newAddPoint = null, $newUsePoint = null) {
1777        $objQuery =& SC_Query::getSingletonInstance();
1778
1779        $arrOrderOld = $objQuery->getRow('dtb_order', 'status, add_point, use_point, customer_id', 'order_id = ?', array($orderId));
1780
1781        // 対応状況が変更無しの場合、DB値を引き継ぐ
1782        if (is_null($newStatus)) {
1783            $newStatus = $arrOrderOld['status'];
1784        }
1785
1786        // 使用ポイント、DB値を引き継ぐ
1787        if (is_null($newUsePoint)) {
1788            $newUsePoint = $arrOrderOld['use_point'];
1789        }
1790
1791        // 加算ポイント、DB値を引き継ぐ
1792        if (is_null($newAddPoint)) {
1793            $newAddPoint = $arrOrderOld['add_point'];
1794        }
1795
1796        if (USE_POINT !== false) {
1797            // 顧客.ポイントの加減値
1798            $addCustomerPoint = 0;
1799
1800            // ▼使用ポイント
1801            // 変更前の対応状況が利用対象の場合、変更前の使用ポイント分を戻す
1802            if (SC_Utils_Ex::sfIsUsePoint($arrOrderOld['status'])) {
1803                $addCustomerPoint += $arrOrderOld['use_point'];
1804            }
1805
1806            // 変更後の対応状況が利用対象の場合、変更後の使用ポイント分を引く
1807            if (SC_Utils_Ex::sfIsUsePoint($newStatus)) {
1808                $addCustomerPoint -= $newUsePoint;
1809            }
1810            // ▲使用ポイント
1811
1812            // ▼加算ポイント
1813            // 変更前の対応状況が加算対象の場合、変更前の加算ポイント分を戻す
1814            if (SC_Utils_Ex::sfIsAddPoint($arrOrderOld['status'])) {
1815                $addCustomerPoint -= $arrOrderOld['add_point'];
1816            }
1817
1818            // 変更後の対応状況が加算対象の場合、変更後の加算ポイント分を足す
1819            if (SC_Utils_Ex::sfIsAddPoint($newStatus)) {
1820                $addCustomerPoint += $newAddPoint;
1821            }
1822            // ▲加算ポイント
1823
1824            if ($addCustomerPoint != 0) {
1825                // ▼顧客テーブルの更新
1826                $sqlval = array();
1827                $where = '';
1828                $arrVal = array();
1829                $arrRawSql = array();
1830                $arrRawSqlVal = array();
1831
1832                $sqlval['update_date'] = 'Now()';
1833                $arrRawSql['point'] = 'point + ?';
1834                $arrRawSqlVal[] = $addCustomerPoint;
1835                $where .= 'customer_id = ?';
1836                $arrVal[] = $arrOrderOld['customer_id'];
1837
1838                $objQuery->update('dtb_customer', $sqlval, $where, $arrVal, $arrRawSql, $arrRawSqlVal);
1839                // ▲顧客テーブルの更新
1840
1841                // 顧客.ポイントをマイナスした場合、
1842                if ($addCustomerPoint < 0) {
1843                    $sql = 'SELECT point FROM dtb_customer WHERE customer_id = ?';
1844                    $point = $objQuery->getOne($sql, array($arrOrderOld['customer_id']));
1845                    // 変更後の顧客.ポイントがマイナスの場合、
1846                    if ($point < 0) {
1847                        // ロールバック
1848                        $objQuery->rollback();
1849                        // エラー
1850                        SC_Utils_Ex::sfDispSiteError(LACK_POINT);
1851                    }
1852                }
1853            }
1854        }
1855
1856        // ▼受注テーブルの更新
1857        $sqlval = array();
1858        if (USE_POINT !== false) {
1859            $sqlval['add_point'] = $newAddPoint;
1860            $sqlval['use_point'] = $newUsePoint;
1861        }
1862        // ステータスが発送済みに変更の場合、発送日を更新
1863        if ($arrOrderOld['status'] != ORDER_DELIV && $newStatus == ORDER_DELIV) {
1864            $sqlval['commit_date'] = 'Now()';
1865        }
1866        // ステータスが入金済みに変更の場合、入金日を更新
1867        elseif ($arrOrderOld['status'] != ORDER_PRE_END && $newStatus == ORDER_PRE_END) {
1868            $sqlval['payment_date'] = 'Now()';
1869        }
1870
1871        $sqlval['status'] = $newStatus;
1872        $sqlval['update_date'] = 'Now()';
1873
1874        $objQuery->update('dtb_order', $sqlval, 'order_id = ?', array($orderId));
1875        // ▲受注テーブルの更新
1876    }
1877
1878    /**
1879     * 指定ファイルが存在する場合 SQL として実行
1880     *
1881     * XXX プラグイン用に追加。将来消すかも。
1882     *
1883     * @param string $sqlFilePath SQL ファイルのパス
1884     * @return void
1885     */
1886    function sfExecSqlByFile($sqlFilePath) {
1887        if (file_exists($sqlFilePath)) {
1888            $objQuery =& SC_Query::getSingletonInstance();
1889
1890            $sqls = file_get_contents($sqlFilePath);
1891            if ($sqls === false) SC_Utils_Ex::sfDispException('ファイルは存在するが読み込めない');
1892
1893            foreach (explode(';', $sqls) as $sql) {
1894                $sql = trim($sql);
1895                if (strlen($sql) == 0) continue;
1896                $objQuery->query($sql);
1897            }
1898        }
1899    }
1900
1901    /**
1902     * 商品規格を設定しているか
1903     *
1904     * @param integer $product_id 商品ID
1905     * @return bool 商品規格が存在する場合:true, それ以外:false
1906     */
1907    function sfHasProductClass($product_id) {
1908        if (!SC_Utils_Ex::sfIsInt($product_id)) return false;
1909
1910        $objQuery =& SC_Query::getSingletonInstance();
1911        $where = 'product_id = ? AND class_combination_id IS NOT NULL';
1912        $count = $objQuery->count('dtb_products_class', $where, array($product_id));
1913
1914        return $count >= 1;
1915    }
1916    /**
1917     * カート内の商品の販売方法判定処理
1918     *
1919     * @param $objCartSess  SC_CartSession  カートセッション
1920     * @return  bool        0:実商品のみ 1:ダウンロード販売と実商品混在 2:全てダウンロード販売
1921     */
1922    function chkCartDown(&$objCartSess, $cartKey = 1) {
1923        $objQuery =& SC_Query::getSingletonInstance();
1924        $down = false;
1925        $nodown = false;
1926        $ret = 0;
1927        $arrID = $objCartSess->getAllProductID();
1928        $table = "dtb_products_class pc";
1929        $where = "pc.product_class_id = ?";
1930        if(!is_null($arrID)){
1931            //カート内のIDから販売方法を取得
1932            foreach ($arrID as $rec) {
1933                $arrRet = $objQuery->select("pc.down AS down", $table, $where, array($rec));
1934                if ($arrRet[0]['down'] == "2"){
1935                    $down = true;
1936                }else{
1937                    $nodown = true;
1938                }
1939            }
1940        }
1941        //混在
1942        if($nodown && $down){
1943            $ret = 1;
1944        //全てダウンロード商品
1945        }else if(!$nodown && $down){
1946            $ret = 2;
1947        }
1948        return $ret;
1949    }
1950
1951    /* 会員情報の住所を一時受注テーブルへ */
1952    function sfRegistDelivData($uniqid, $objCustomer) {
1953
1954        // 登録データの作成
1955        $sqlval['order_temp_id'] = $uniqid;
1956        $sqlval['update_date'] = 'Now()';
1957        $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
1958        $sqlval['deliv_check'] = '-1';
1959        $sqlval['order_name01'] = $objCustomer->getValue('name01');
1960        $sqlval['order_name02'] = $objCustomer->getValue('name02');
1961        $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
1962        $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
1963        $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
1964        $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
1965        $sqlval['order_pref'] = $objCustomer->getValue('pref');
1966        $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
1967        $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
1968        $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
1969        $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
1970        $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
1971        $sqlval['order_fax01'] = $objCustomer->getValue('fax01');
1972        $sqlval['order_fax02'] = $objCustomer->getValue('fax02');
1973        $sqlval['order_fax03'] = $objCustomer->getValue('fax03');
1974        $sqlval['deliv_name01'] = $objCustomer->getValue('name01');
1975        $sqlval['deliv_name02'] = $objCustomer->getValue('name02');
1976        $sqlval['deliv_kana01'] = $objCustomer->getValue('kana01');
1977        $sqlval['deliv_kana02'] = $objCustomer->getValue('kana02');
1978        $sqlval['deliv_zip01'] = $objCustomer->getValue('zip01');
1979        $sqlval['deliv_zip02'] = $objCustomer->getValue('zip02');
1980        $sqlval['deliv_pref'] = $objCustomer->getValue('pref');
1981        $sqlval['deliv_addr01'] = $objCustomer->getValue('addr01');
1982        $sqlval['deliv_addr02'] = $objCustomer->getValue('addr02');
1983        $sqlval['deliv_tel01'] = $objCustomer->getValue('tel01');
1984        $sqlval['deliv_tel02'] = $objCustomer->getValue('tel02');
1985        $sqlval['deliv_tel03'] = $objCustomer->getValue('tel03');
1986        $sqlval['deliv_fax01'] = $objCustomer->getValue('fax01');
1987        $sqlval['deliv_fax02'] = $objCustomer->getValue('fax02');
1988        $sqlval['deliv_fax03'] = $objCustomer->getValue('fax03');
1989
1990        $this->sfRegistTempOrder($uniqid, $sqlval);
1991    }
1992}
1993?>
Note: See TracBrowser for help on using the repository browser.