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

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

規格まわりの内部構成変更に伴う修正(#781)

  • 規格のデータ構造を木構造へ変更
  • 商品検索ロジックを SC_Product クラスへできるだけ集約
  • 以下の VIEW を削除
    • vw_category_count;
    • vw_product_class;
    • vw_products_nonclass;
    • vw_cross_products_class;
    • vw_cross_class;
    • vw_download_class;
  • 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             * FIXME パフォーマンスに問題があるため SC_Product::lists() を使用する
113             */
114            // 読み込む列とテーブルの指定
115            $col = "DISTINCT T1.product_id, product_code_min, product_code_max,"
116                . " price01_min, price01_max, price02_min, price02_max,"
117                . " stock_min, stock_max, stock_unlimited_min,"
118                . " stock_unlimited_max, del_flg, status, name, comment1,"
119                . " comment2, comment3, main_list_comment, main_image,"
120                . " main_list_image, deliv_date_id, sale_limit,"
121                . " point_rate, create_date, deliv_fee, "
122                . " T4.product_rank, T4.category_rank";
123            $from = "vw_products_allclass AS T1"
124                . " JOIN ("
125                . " SELECT max(T3.rank) AS category_rank,"
126                . "        max(T2.rank) AS product_rank,"
127                . "        T2.product_id"
128                . "   FROM dtb_product_categories T2"
129                . "   JOIN dtb_category T3 USING (category_id)"
130                . " GROUP BY product_id) AS T4 USING (product_id)";
131            $order = "T4.category_rank DESC, T4.product_rank DESC";
132
133            // 行数の取得
134            if (empty($arrval)) {
135                $arrval = array();
136            }
137            $linemax = $objQuery->count("dtb_products", $where, $arrval);
138            $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
139
140            // ページ送りの処理
141            if(isset($_POST['search_page_max'])
142               && is_numeric($_POST['search_page_max'])) {
143                $page_max = $_POST['search_page_max'];
144            } else {
145                $page_max = SEARCH_PMAX;
146            }
147
148            // ページ送りの取得
149            $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchOnlyPage", NAVI_PMAX);
150            $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列
151            $startno = $objNavi->start_row;
152
153            // 取得範囲の指定(開始行番号、行数のセット)
154            $objQuery->setLimitOffset($page_max, $startno);
155            // 表示順序
156            $objQuery->setOrder($order);
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    // FIXME SC_Product クラスを使用する
212    /* 規格セレクトボックスの作成 */
213    function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
214
215        $classcat_find1 = false;
216        $classcat_find2 = false;
217        // 在庫ありの商品の有無
218        $stock_find = false;
219
220        // 商品規格情報の取得
221        $arrProductsClass = $this->lfGetProductsClass($product_id);
222
223        // 規格1クラス名の取得
224        $this->tpl_class_name1[$product_id] =
225            isset($arrClassName[$arrProductsClass[0]['class_id1']])
226            ? $arrClassName[$arrProductsClass[0]['class_id1']]
227            : "";
228
229        // 規格2クラス名の取得
230        $this->tpl_class_name2[$product_id] =
231            isset($arrClassName[$arrProductsClass[0]['class_id2']])
232            ? $arrClassName[$arrProductsClass[0]['class_id2']]
233            : "";
234
235        // すべての組み合わせ数
236        $count = count($arrProductsClass);
237
238        $classcat_id1 = "";
239
240        $arrSele = array();
241        $arrList = array();
242
243        $list_id = 0;
244        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
245        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
246
247        for ($i = 0; $i < $count; $i++) {
248            // 在庫のチェック
249            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
250                continue;
251            }
252
253            $stock_find = true;
254
255            // 規格1のセレクトボックス用
256            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
257                $arrList[$list_id].=");\n";
258                $arrVal[$list_id].=");\n";
259                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
260                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
261                $list_id++;
262
263                $arrList[$list_id] = "";
264                $arrVal[$list_id] = "";
265            }
266
267            // 規格2のセレクトボックス用
268            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
269
270            // セレクトボックス表示値
271            if($arrList[$list_id] == "") {
272                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
273            } else {
274                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
275            }
276
277            // セレクトボックスPOST値
278            if($arrVal[$list_id] == "") {
279                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
280            } else {
281                $arrVal[$list_id].= ", '".$classcat_id2."'";
282            }
283        }
284
285        $arrList[$list_id].=");\n";
286        $arrVal[$list_id].=");\n";
287
288        // 規格1
289        $this->arrClassCat1[$product_id] = $arrSele;
290
291        $lists = "\tlists".$product_id. " = new Array(";
292        $no = 0;
293        foreach($arrList as $val) {
294            $this->tpl_javascript.= $val;
295            if ($no != 0) {
296                $lists.= ",list". $product_id. "_". $no;
297            } else {
298                $lists.= "list". $product_id. "_". $no;
299            }
300            $no++;
301        }
302        $this->tpl_javascript.= $lists.");\n";
303
304        $vals = "\tvals".$product_id. " = new Array(";
305        $no = 0;
306        foreach($arrVal as $val) {
307            $this->tpl_javascript.= $val;
308            if ($no != 0) {
309                $vals.= ",val". $product_id. "_". $no;
310            } else {
311                $vals.= "val". $product_id. "_". $no;
312            }
313            $no++;
314        }
315        $this->tpl_javascript.= $vals.");\n";
316
317        // 選択されている規格2ID
318        $classcategory_id = "classcategory_id". $product_id;
319
320        $classcategory_id_2 = $classcategory_id . "_2";
321        if (!isset($classcategory_id_2)) $classcategory_id_2 = "";
322        if (!isset($_POST[$classcategory_id_2])) $_POST[$classcategory_id_2] = "";
323
324        $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', "
325            . "'" . $classcategory_id_2 . "',"
326            . "'" . $product_id . "',"
327            . "'" . $_POST[$classcategory_id_2] ."'); ";
328
329        // 規格1が設定されている
330        if($arrProductsClass[0]['classcategory_id1'] != '0') {
331            $classcat_find1 = true;
332        }
333
334        // 規格2が設定されている
335        if($arrProductsClass[0]['classcategory_id2'] != '0') {
336            $classcat_find2 = true;
337        }
338
339        $this->tpl_classcat_find1[$product_id] = $classcat_find1;
340        $this->tpl_classcat_find2[$product_id] = $classcat_find2;
341        $this->tpl_stock_find[$product_id] = $stock_find;
342    }
343
344    /* 商品規格情報の取得 */
345    function lfGetProductsClass($product_id) {
346        $arrRet = array();
347        if(SC_Utils_Ex::sfIsInt($product_id)) {
348            // 商品規格取得
349            $objQuery = new SC_Query();
350            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
351            $table = "vw_product_class AS prdcls";
352            $where = "product_id = ?";
353            $objQuery->setOrder("rank1 DESC, rank2 DESC");
354            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
355        }
356        return $arrRet;
357    }
358}
359?>
Note: See TracBrowser for help on using the repository browser.