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

Revision 19684, 7.9 KB checked in by nanasess, 13 years ago (diff)

#635 処理の単純化

  • Service/JSON.php の宣言を html/require_class.php へ移動
  • 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
2<?php
3/*
4 * This file is part of EC-CUBE
5 *
6 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
7 *
8 * http://www.lockon.co.jp/
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24
25// {{{ requires
26require_once(CLASS_PATH . "pages/admin/LC_Page_Admin.php");
27
28/**
29 * 商品選択 のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Order_ProductSelect extends LC_Page_Admin {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'order/product_select.tpl';
48        $this->tpl_mainno = 'order';
49        $this->tpl_subnavi = '';
50        $this->tpl_subno = "";
51        $this->tpl_subtitle = '商品選択';
52    }
53
54    /**
55     * Page のプロセス.
56     *
57     * @return void
58     */
59    function process() {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    function action() {
70        $objSess = new SC_Session();
71        $objDb = new SC_Helper_DB_Ex();
72
73        // 認証可否の判定
74        SC_Utils_Ex::sfIsSuccess($objSess);
75
76        if (!isset($_POST['mode'])) $_POST['mode'] = "";
77
78        if ($_GET['no'] != '') {
79            $this->tpl_no = strval($_GET['no']);
80        } elseif ($_POST['no'] != '') {
81            $this->tpl_no = strval($_POST['no']);
82        }
83
84        if ($_POST['mode'] == "search") {
85
86            // POST値の引き継ぎ
87            $this->arrForm = $_POST;
88            // 入力文字の強制変換
89            $this->lfConvertParam();
90
91            $where = "alldtl.del_flg = 0";
92            $arrval = array();
93
94            /* 入力エラーなし */
95            foreach ($this->arrForm as $key => $val) {
96                if($val == "") {
97                    continue;
98                }
99
100                switch ($key) {
101                case 'search_name':
102                    $where .= " AND name ILIKE ?";
103                    $arrval[] = "%$val%";
104                    break;
105                case 'search_category_id':
106                    list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($val);
107                    if($tmp_where != "") {
108                        $where.= " AND alldtl.product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")";
109                        $arrval = array_merge((array)$arrval, (array)$tmp_arrval);
110                    }
111                    break;
112                case 'search_product_code':
113                    $where .= " AND alldtl.product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ? GROUP BY product_id)";
114                    $arrval[] = "$val%";
115                    break;
116                default:
117                    break;
118                }
119            }
120
121            // 検索結果対象となる商品の数を取得
122            $objQuery =& SC_Query::getSingletonInstance();
123            $objQuery->setWhere($where);
124            $objProduct = new SC_Product();
125            $linemax = $objProduct->findProductCount($objQuery, $arrval);
126            $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用
127
128            // ページ送りの処理
129            if(isset($_POST['search_page_max'])
130               && is_numeric($_POST['search_page_max'])) {
131                $page_max = $_POST['search_page_max'];
132            } else {
133                $page_max = SEARCH_PMAX;
134            }
135
136            // ページ送りの取得
137            $objNavi = new SC_PageNavi($_POST['search_pageno'], $linemax, $page_max, "fnNaviSearchOnlyPage", NAVI_PMAX);
138            $this->tpl_strnavi = $objNavi->strnavi;     // 表示文字列
139            $startno = $objNavi->start_row;
140
141            $objProduct = new SC_Product();
142            $objQuery =& SC_Query::getSingletonInstance();
143            $objQuery->setWhere($where);
144
145            // 取得範囲の指定(開始行番号、行数のセット)
146            $objQuery->setLimitOffset($page_max, $startno);
147            // 表示順序
148            $objQuery->setOrder($order);
149
150            // 検索結果の取得
151            $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, $arrval);
152
153            $where = "";
154            if (is_array($arrProduct_id) && !empty($arrProduct_id)) {
155                $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')';
156            } else {
157                // 一致させない
158                $where = '0<>0';
159            }
160            $objQuery =& SC_Query::getSingletonInstance();
161            $objQuery->setWhere($where);
162            $arrProducts = $objProduct->lists($objQuery, $arrProduct_id);
163
164            //取得している並び順で並び替え
165            $arrProducts2 = array();
166            foreach($arrProducts as $item) {
167                $arrProducts2[ $item['product_id'] ] = $item;
168            }
169            $this->arrProducts = array();
170            foreach($arrProduct_id as $product_id) {
171                $this->arrProducts[] = $arrProducts2[$product_id];
172            }
173
174            $objProduct->setProductsClassByProductIds($arrProduct_id);
175            $objJson = new Services_JSON();
176            $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($objProduct->classCategories) . '; ';
177
178            foreach ($this->arrProducts as $arrProduct) {
179                $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n";
180            }
181
182            $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}';
183            $this->tpl_onload .= 'fnOnLoad(); ';
184
185            // 規格1クラス名
186            $this->tpl_class_name1 = $objProduct->className1;
187
188            // 規格2クラス名
189            $this->tpl_class_name2 = $objProduct->className2;
190
191            // 規格1
192            $this->arrClassCat1 = $objProduct->classCats1;
193
194            // 規格1が設定されている
195            $this->tpl_classcat_find1 = $objProduct->classCat1_find;
196            // 規格2が設定されている
197            $this->tpl_classcat_find2 = $objProduct->classCat2_find;
198            $this->tpl_product_class_id = $objProduct->product_class_id;
199            $this->tpl_stock_find = $objProduct->stock_find;
200        }
201
202        // カテゴリ取得
203        $this->arrCatList = $objDb->sfGetCategoryList();
204    }
205
206    /**
207     * デストラクタ.
208     *
209     * @return void
210     */
211    function destroy() {
212        parent::destroy();
213    }
214
215    /* 取得文字列の変換 */
216    function lfConvertParam() {
217        /*
218         *  文字列の変換
219         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
220         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
221         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
222         *  n :  「全角」数字を「半角(ハンカク)」に変換
223         */
224        $arrConvList['search_name'] = "KVa";
225        $arrConvList['search_product_code'] = "KVa";
226
227        // 文字変換
228        foreach ($arrConvList as $key => $val) {
229            // POSTされてきた値のみ変換する。
230            if(isset($this->arrForm[$key])) {
231                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
232            }
233        }
234    }
235}
236?>
Note: See TracBrowser for help on using the repository browser.