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

Revision 18007, 13.6 KB checked in by kajiwara, 15 years ago (diff)

2.4.0 正式版のコミット。コミット内容の詳細はこちら(http://svn.ec-cube.net/open_trac/query?status=closed&milestone=EC-CUBE2.4.0

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