source: branches/version-2_5-dev/data/class/pages/admin/order/LC_Page_Admin_Order_ProductSelect.php @ 18772

Revision 18772, 12.6 KB checked in by nanasess, 14 years ago (diff)

r18700 の続き

  • SC_DbConn のインスタンスを直接使用している個所を SC_Query に変更(#565)
    • 削除予定の機能については未対応
  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • 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// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 商品選択 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Order_ProductSelect extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'order/product_select.tpl';
47        $this->tpl_mainno = 'order';
48        $this->tpl_subnavi = '';
49        $this->tpl_subno = "";
50        $this->tpl_subtitle = '商品選択';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $objView = new SC_AdminView();
60        $objSess = new SC_Session();
61        $objDb = new SC_Helper_DB_Ex();
62        $objQuery = new SC_Query();
63
64        // 認証可否の判定
65        SC_Utils_Ex::sfIsSuccess($objSess);
66
67        if (!isset($_POST['mode'])) $_POST['mode'] = "";
68
69        if ($_GET['no'] != '') {
70            $this->tpl_no = strval($_GET['no']);
71        } elseif ($_POST['no'] != '') {
72            $this->tpl_no = strval($_POST['no']);
73        }
74
75        if ($_POST['mode'] == "search") {
76
77            // POST値の引き継ぎ
78            $this->arrForm = $_POST;
79            // 入力文字の強制変換
80            $this->lfConvertParam();
81
82            $where = "del_flg = 0";
83
84            /* 入力エラーなし */
85            foreach ($this->arrForm as $key => $val) {
86                if($val == "") {
87                    continue;
88                }
89
90                switch ($key) {
91                case 'search_name':
92                    $where .= " AND name ILIKE ?";
93                    $arrval[] = "%$val%";
94                    break;
95                case 'search_category_id':
96                    list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val);
97                    if($tmp_where != "") {
98                        $where.= " AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
99                        $arrval = array_merge((array)$arrval, (array)$tmp_arrval);
100                    }
101                    break;
102                case 'search_product_code':
103                    $where .= " AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)";
104                    $arrval[] = "$val%";
105                    break;
106                default:
107                    break;
108                }
109            }
110
111            // 読み込む列とテーブルの指定
112            $col = "DISTINCT T1.product_id, product_code_min, product_code_max,"
113                . " price01_min, price01_max, price02_min, price02_max,"
114                . " stock_min, stock_max, stock_unlimited_min,"
115                . " stock_unlimited_max, del_flg, status, name, comment1,"
116                . " comment2, comment3, main_list_comment, main_image,"
117                . " main_list_image, product_flag, deliv_date_id, sale_limit,"
118                . " point_rate, create_date, deliv_fee, "
119                . " T4.product_rank, T4.category_rank";
120            $from = "vw_products_allclass AS T1"
121                . " JOIN ("
122                . " SELECT max(T3.rank) AS category_rank,"
123                . "        max(T2.rank) AS product_rank,"
124                . "        T2.product_id"
125                . "   FROM dtb_product_categories T2"
126                . "   JOIN dtb_category T3 USING (category_id)"
127                . " GROUP BY product_id) AS T4 USING (product_id)";
128            $order = "T4.category_rank DESC, T4.product_rank DESC";
129
130            // 行数の取得
131            if (empty($arrval)) {
132                $arrval = array();
133            }
134            $linemax = $objQuery->count("dtb_products", $where, $arrval);
135            $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
136
137            // ページ送りの処理
138            if(isset($_POST['search_page_max'])
139               && is_numeric($_POST['search_page_max'])) {
140                $page_max = $_POST['search_page_max'];
141            } else {
142                $page_max = SEARCH_PMAX;
143            }
144
145            // ページ送りの取得
146            $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchOnlyPage", NAVI_PMAX);
147            $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列
148            $startno = $objNavi->start_row;
149
150            // 取得範囲の指定(開始行番号、行数のセット)
151            if(DB_TYPE != "mysql") $objQuery->setLimitOffset($page_max, $startno);
152            // 表示順序
153            $objQuery->setOrder($order);
154
155            // viewも絞込みをかける(mysql用)
156            //sfViewWhere("&&noncls_where&&", $where, $arrval, $objQuery->order . " " .  $objQuery->setLimitOffset($page_max, $startno, true));
157
158            // 検索結果の取得
159            $this->arrProducts = $objQuery->select($col, $from, $where, $arrval);
160
161            // 規格名一覧
162            $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
163
164            // 規格分類名一覧
165            $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
166
167            // 規格セレクトボックス設定
168            for($i = 0; $i < count($this->arrProducts); $i++) {
169                $this->lfMakeSelect($this->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
170            }
171        }
172
173        // カテゴリ取得
174        $this->arrCatList = $objDb->sfGetCategoryList();
175
176        //---- ページ表示
177        $objView->assignobj($this);
178        $objView->display($this->tpl_mainpage);
179    }
180
181    /**
182     * デストラクタ.
183     *
184     * @return void
185     */
186    function destroy() {
187        parent::destroy();
188    }
189
190    /* 取得文字列の変換 */
191    function lfConvertParam() {
192        /*
193         *  文字列の変換
194         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
195         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
196         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
197         *  n :  「全角」数字を「半角(ハンカク)」に変換
198         */
199        $arrConvList['search_name'] = "KVa";
200        $arrConvList['search_product_code'] = "KVa";
201
202        // 文字変換
203        foreach ($arrConvList as $key => $val) {
204            // POSTされてきた値のみ変換する。
205            if(isset($this->arrForm[$key])) {
206                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
207            }
208        }
209    }
210
211    /* 規格セレクトボックスの作成 */
212    function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
213
214        $classcat_find1 = false;
215        $classcat_find2 = false;
216        // 在庫ありの商品の有無
217        $stock_find = false;
218
219        // 商品規格情報の取得
220        $arrProductsClass = $this->lfGetProductsClass($product_id);
221
222        // 規格1クラス名の取得
223        $this->tpl_class_name1[$product_id] =
224            isset($arrClassName[$arrProductsClass[0]['class_id1']])
225            ? $arrClassName[$arrProductsClass[0]['class_id1']]
226            : "";
227
228        // 規格2クラス名の取得
229        $this->tpl_class_name2[$product_id] =
230            isset($arrClassName[$arrProductsClass[0]['class_id2']])
231            ? $arrClassName[$arrProductsClass[0]['class_id2']]
232            : "";
233
234        // すべての組み合わせ数
235        $count = count($arrProductsClass);
236
237        $classcat_id1 = "";
238
239        $arrSele = array();
240        $arrList = array();
241
242        $list_id = 0;
243        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
244        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
245
246        for ($i = 0; $i < $count; $i++) {
247            // 在庫のチェック
248            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
249                continue;
250            }
251
252            $stock_find = true;
253
254            // 規格1のセレクトボックス用
255            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
256                $arrList[$list_id].=");\n";
257                $arrVal[$list_id].=");\n";
258                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
259                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
260                $list_id++;
261
262                $arrList[$list_id] = "";
263                $arrVal[$list_id] = "";
264            }
265
266            // 規格2のセレクトボックス用
267            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
268
269            // セレクトボックス表示値
270            if($arrList[$list_id] == "") {
271                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
272            } else {
273                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
274            }
275
276            // セレクトボックスPOST値
277            if($arrVal[$list_id] == "") {
278                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
279            } else {
280                $arrVal[$list_id].= ", '".$classcat_id2."'";
281            }
282        }
283
284        $arrList[$list_id].=");\n";
285        $arrVal[$list_id].=");\n";
286
287        // 規格1
288        $this->arrClassCat1[$product_id] = $arrSele;
289
290        $lists = "\tlists".$product_id. " = new Array(";
291        $no = 0;
292        foreach($arrList as $val) {
293            $this->tpl_javascript.= $val;
294            if ($no != 0) {
295                $lists.= ",list". $product_id. "_". $no;
296            } else {
297                $lists.= "list". $product_id. "_". $no;
298            }
299            $no++;
300        }
301        $this->tpl_javascript.= $lists.");\n";
302
303        $vals = "\tvals".$product_id. " = new Array(";
304        $no = 0;
305        foreach($arrVal as $val) {
306            $this->tpl_javascript.= $val;
307            if ($no != 0) {
308                $vals.= ",val". $product_id. "_". $no;
309            } else {
310                $vals.= "val". $product_id. "_". $no;
311            }
312            $no++;
313        }
314        $this->tpl_javascript.= $vals.");\n";
315
316        // 選択されている規格2ID
317        $classcategory_id = "classcategory_id". $product_id;
318
319        $classcategory_id_2 = $classcategory_id . "_2";
320        if (!isset($classcategory_id_2)) $classcategory_id_2 = "";
321        if (!isset($_POST[$classcategory_id_2])) $_POST[$classcategory_id_2] = "";
322
323        $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', "
324            . "'" . $classcategory_id_2 . "',"
325            . "'" . $product_id . "',"
326            . "'" . $_POST[$classcategory_id_2] ."'); ";
327
328        // 規格1が設定されている
329        if($arrProductsClass[0]['classcategory_id1'] != '0') {
330            $classcat_find1 = true;
331        }
332
333        // 規格2が設定されている
334        if($arrProductsClass[0]['classcategory_id2'] != '0') {
335            $classcat_find2 = true;
336        }
337
338        $this->tpl_classcat_find1[$product_id] = $classcat_find1;
339        $this->tpl_classcat_find2[$product_id] = $classcat_find2;
340        $this->tpl_stock_find[$product_id] = $stock_find;
341    }
342
343    /* 商品規格情報の取得 */
344    function lfGetProductsClass($product_id) {
345        $arrRet = array();
346        if(SC_Utils_Ex::sfIsInt($product_id)) {
347            // 商品規格取得
348            $objQuery = new SC_Query();
349            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
350            $table = "vw_product_class AS prdcls";
351            $where = "product_id = ?";
352            $objQuery->setOrder("rank1 DESC, rank2 DESC");
353            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
354        }
355        return $arrRet;
356    }
357}
358?>
Note: See TracBrowser for help on using the repository browser.