source: branches/feature-module-update/data/class/pages/products/LC_Page_Products_List.php @ 15354

Revision 15354, 17.2 KB checked in by nanasess, 17 years ago (diff)

リファクタリングと未定義変数の修正

  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to application/x-httpd-php
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8// {{{ requires
9require_once(CLASS_PATH . "pages/LC_Page.php");
10
11/**
12 * 商品一覧 のページクラス.
13 *
14 * @package Page
15 * @author LOCKON CO.,LTD.
16 * @version $Id$
17 */
18class LC_Page_Products_List extends LC_Page {
19
20    // {{{ properties
21
22    /** テンプレートクラス名1 */
23    var $tpl_class_name1;
24
25    /** テンプレートクラス名2 */
26    var $tpl_class_name2;
27
28    /** JavaScript テンプレート */
29    var $tpl_javascript;
30
31    // }}}
32    // {{{ functions
33
34    /**
35     * Page を初期化する.
36     *
37     * @return void
38     */
39    function init() {
40        parent::init();
41
42        $masterData = new SC_DB_MasterData_Ex();
43        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
44        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
45        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
46        $this->arrPRODUCTLISTMAX = $masterData->getMasterData("mtb_product_list_max");
47
48        $this->tpl_class_name1 = array();
49        $this->tpl_class_name2 = array();
50        $this->allowClientCache();
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $conn = new SC_DBConn();
60        $objDb = new SC_Helper_DB_Ex();
61
62        //表示件数の選択
63        if(isset($_POST['disp_number'])
64           && SC_Utils_Ex::sfIsInt($_POST['disp_number'])) {
65            $this->disp_number = $_POST['disp_number'];
66        } else {
67            //最小表示件数を選択
68            $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX));
69        }
70
71        //表示順序の保存
72        $this->orderby = isset($_POST['orderby']) ? $_POST['orderby'] : "";
73
74        // GETのカテゴリIDを元に正しいカテゴリIDを取得する。
75        $category_id = SC_Utils_Ex::sfGetCategoryId("", $_GET['category_id']);
76
77        if (!isset($_GET['mode'])) $_GET['mode'] = "";
78        if (!isset($_GET['name'])) $_GET['name'] = "";
79        if (!isset($_POST['orderby'])) $_POST['orderby'] = "";
80
81        // タイトル編集
82        $tpl_subtitle = "";
83        if ($_GET['mode'] == 'search') {
84            $tpl_subtitle = "検索結果";
85        } elseif ($category_id == "" ) {
86            $tpl_subtitle = "全商品";
87        } else {
88            $arrFirstCat = SC_Utils_Ex::sfGetFirstCat($category_id);
89            $tpl_subtitle = $arrFirstCat['name'];
90        }
91
92        $objQuery = new SC_Query();
93        $count = $objQuery->count("dtb_best_products", "category_id = ?", array($category_id));
94
95        // 以下の条件でBEST商品を表示する
96        // ・BEST最大数の商品が登録されている。
97        // ・カテゴリIDがルートIDである。
98        // ・検索モードでない。
99        if(($count >= BEST_MIN) && $this->lfIsRootCategory($category_id) && ($_GET['mode'] != 'search') ) {
100            // 商品TOPの表示処理
101            /** 必ず指定する **/
102            $this->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // メインテンプレート
103
104            $this->arrBestItems = SC_Utils_Ex::sfGetBestProducts($conn, $category_id);
105            $this->BEST_ROOP_MAX = ceil((BEST_MAX-1)/2);
106        } else {
107            if ($_GET['mode'] == 'search' && strlen($_GET['category_id']) == 0 ){
108                // 検索時にcategory_idがGETに存在しない場合は、仮に埋めたIDを空白に戻す
109                $category_id = '';
110            }
111
112            // 商品一覧の表示処理
113            $this = $this->lfDispProductsList($category_id, $_GET['name'], $this->disp_number, $_POST['orderby']);
114
115            // 検索条件を画面に表示
116            // カテゴリー検索条件
117            if (strlen($_GET['category_id']) == 0) {
118                $arrSearch['category'] = "指定なし";
119            }else{
120                $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id));
121                $arrSearch['category'] = $arrCat;
122            }
123
124            // 商品名検索条件
125            if ($_GET['name'] === "") {
126                $arrSearch['name'] = "指定なし";
127            }else{
128                $arrSearch['name'] = $_GET['name'];
129            }
130        }
131
132        // レイアウトデザインを取得
133        $layout = new SC_Helper_PageLayout_Ex();
134        $this = $layout->sfGetPageLayout($this, false, "products/list.php");
135
136        if(isset($_POST['mode']) && $_POST['mode'] == "cart"
137           && $_POST['product_id'] != "") {
138
139            // 値の正当性チェック
140            if(!SC_Utils_Ex::sfIsInt($_POST['product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $_POST['product_id'], "del_flg = 0 AND status = 1")) {
141                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
142            } else {
143                // 入力値の変換
144                $this->arrErr = $this->lfCheckError($_POST['product_id']);
145                if(count($this->arrErr) == 0) {
146                    $objCartSess = new SC_CartSession();
147                    $classcategory_id = "classcategory_id". $_POST['product_id'];
148                    $classcategory_id1 = $_POST[$classcategory_id. '_1'];
149                    $classcategory_id2 = $_POST[$classcategory_id. '_2'];
150                    $quantity = "quantity". $_POST['product_id'];
151                    // 規格1が設定されていない場合
152                    if(!$this->tpl_classcat_find1[$_POST['product_id']]) {
153                        $classcategory_id1 = '0';
154                    }
155                    // 規格2が設定されていない場合
156                    if(!$this->tpl_classcat_find2[$_POST['product_id']]) {
157                        $classcategory_id2 = '0';
158                    }
159                    $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
160                    $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]);
161                    $this->sendRedirect($this->getLocation(URL_CART_TOP));
162                    exit;
163                }
164            }
165        }
166
167        $this->tpl_subtitle = $tpl_subtitle;
168
169        // 支払方法の取得
170        $this->arrPayment = $this->lfGetPayment();
171        // 入力情報を渡す
172        $this->arrForm = $_POST;
173
174        $this->lfConvertParam();
175
176        $this->category_id = $category_id;
177        $this->arrSearch = $arrSearch;
178
179        SC_Utils_Ex::sfCustomDisplay($this);
180    }
181
182    /**
183     * デストラクタ.
184     *
185     * @return void
186     */
187    function destroy() {
188        parent::destroy();
189    }
190
191    /* カテゴリIDがルートかどうかの判定 */
192    function lfIsRootCategory($category_id) {
193        $objQuery = new SC_Query();
194        $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id));
195        if($level == 1) {
196            return true;
197        }
198        return false;
199    }
200
201    /* 商品一覧の表示 */
202    function lfDispProductsList($category_id, $name, $disp_num, $orderby) {
203
204        $objQuery = new SC_Query();
205        $objDb = new SC_Helper_DB_Ex();
206        $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : "";
207
208        //表示件数でテンプレートを切り替える
209        $this->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl";        // メインテンプレート
210
211        //表示順序
212        switch($orderby) {
213        //価格順
214        case 'price':
215            $order = "price02_min ASC";
216            break;
217        //新着順
218        case 'date':
219            $order = "create_date DESC";
220            break;
221        default:
222            $order = "category_rank DESC, rank DESC";
223            break;
224        }
225
226        // 商品検索条件の作成(未削除、表示)
227        $where = "del_flg = 0 AND status = 1 ";
228        // カテゴリからのWHERE文字列取得
229        if ( $category_id ) {
230            list($tmp_where, $arrval) = $objDb->sfGetCatWhere($category_id);
231            if($tmp_where != "") {
232                $where.= " AND $tmp_where";
233            }
234        }
235
236        // 商品名をwhere文に
237        $name = ereg_replace(",", "", $name);
238        if ( strlen($name) > 0 ){
239            $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) ";
240            $ret = SC_Utils_Ex::sfManualEscape($name);
241            $arrval[] = "%$ret%";
242            $arrval[] = "%$ret%";
243        }
244
245        // 行数の取得
246        $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval);
247        $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用
248
249        // ページ送りの取得
250        $objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $disp_num, "fnNaviPage", NAVI_PMAX);
251
252        $strnavi = $objNavi->strnavi;
253        $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi);
254        $this->tpl_strnavi = $strnavi;       // 表示文字列
255        $startno = $objNavi->start_row;                 // 開始行
256
257        // 取得範囲の指定(開始行番号、行数のセット)
258        $objQuery->setlimitoffset($disp_num, $startno);
259        // 表示順序
260        $objQuery->setorder($order);
261
262        // 検索結果の取得
263        $this->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval);
264
265        // 規格名一覧
266        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
267        // 規格分類名一覧
268        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
269        // 企画セレクトボックス設定
270        if($disp_num == 15) {
271            for($i = 0; $i < count($this->arrProducts); $i++) {
272                $this = $this->lfMakeSelect($this->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
273                // 購入制限数を取得
274                $this = $this->lfGetSaleLimit($this->arrProducts[$i]);
275            }
276        }
277
278        return $this;
279    }
280
281    /* 規格セレクトボックスの作成 */
282    function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
283
284        $classcat_find1 = false;
285        $classcat_find2 = false;
286        // 在庫ありの商品の有無
287        $stock_find = false;
288
289        // 商品規格情報の取得
290        $arrProductsClass = $this->lfGetProductsClass($product_id);
291
292        // 規格1クラス名の取得
293        $this->tpl_class_name1[$product_id] =
294            isset($arrClassName[$arrProductsClass[0]['class_id1']])
295            ? $arrClassName[$arrProductsClass[0]['class_id1']]
296            : "";
297
298        // 規格2クラス名の取得
299        $this->tpl_class_name2[$product_id] =
300            isset($arrClassName[$arrProductsClass[0]['class_id2']])
301            ? $arrClassName[$arrProductsClass[0]['class_id2']]
302            : "";
303
304        // すべての組み合わせ数
305        $count = count($arrProductsClass);
306
307        $classcat_id1 = "";
308
309        $arrSele = array();
310        $arrList = array();
311
312        $list_id = 0;
313        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
314        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
315
316        for ($i = 0; $i < $count; $i++) {
317            // 在庫のチェック
318            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
319                continue;
320            }
321
322            $stock_find = true;
323
324            // 規格1のセレクトボックス用
325            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
326                $arrList[$list_id].=");\n";
327                $arrVal[$list_id].=");\n";
328                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
329                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
330                $list_id++;
331
332                $arrList[$list_id] = "";
333                $arrVal[$list_id] = "";
334            }
335
336            // 規格2のセレクトボックス用
337            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
338
339            // セレクトボックス表示値
340            if($arrList[$list_id] == "") {
341                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
342            } else {
343                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
344            }
345
346            // セレクトボックスPOST値
347            if($arrVal[$list_id] == "") {
348                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
349            } else {
350                $arrVal[$list_id].= ", '".$classcat_id2."'";
351            }
352        }
353
354        $arrList[$list_id].=");\n";
355        $arrVal[$list_id].=");\n";
356
357        // 規格1
358        $this->arrClassCat1[$product_id] = $arrSele;
359
360        $lists = "\tlists".$product_id. " = new Array(";
361        $no = 0;
362        foreach($arrList as $val) {
363            $this->tpl_javascript.= $val;
364            if ($no != 0) {
365                $lists.= ",list". $product_id. "_". $no;
366            } else {
367                $lists.= "list". $product_id. "_". $no;
368            }
369            $no++;
370        }
371        $this->tpl_javascript.= $lists.");\n";
372
373        $vals = "\tvals".$product_id. " = new Array(";
374        $no = 0;
375        foreach($arrVal as $val) {
376            $this->tpl_javascript.= $val;
377            if ($no != 0) {
378                $vals.= ",val". $product_id. "_". $no;
379            } else {
380                $vals.= "val". $product_id. "_". $no;
381            }
382            $no++;
383        }
384        $this->tpl_javascript.= $vals.");\n";
385
386        // 選択されている規格2ID
387        $classcategory_id = "classcategory_id". $product_id;
388
389        $classcategory_id_2 = $classcategory_id . "_2";
390        if (!isset($$classcategory_id_2)) $$classcategory_id_2 = "";
391        if (!isset($_POST[$$classcategory_id_2])) $_POST[$$classcategory_id_2] = "";
392
393        $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', "
394            . "'" . $$classcategory_id_2 . "',"
395            . "'" . $product_id . "',"
396            . "'" . $_POST[$$classcategory_id_2] ."'); ";
397
398        // 規格1が設定されている
399        if($arrProductsClass[0]['classcategory_id1'] != '0') {
400            $classcat_find1 = true;
401        }
402
403        // 規格2が設定されている
404        if($arrProductsClass[0]['classcategory_id2'] != '0') {
405            $classcat_find2 = true;
406        }
407
408        $this->tpl_classcat_find1[$product_id] = $classcat_find1;
409        $this->tpl_classcat_find2[$product_id] = $classcat_find2;
410        $this->tpl_stock_find[$product_id] = $stock_find;
411
412        return $this;
413    }
414    /* 商品規格情報の取得 */
415    function lfGetProductsClass($product_id) {
416        $arrRet = array();
417        if(SC_Utils_Ex::sfIsInt($product_id)) {
418            // 商品規格取得
419            $objQuery = new SC_Query();
420            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
421            $table = "vw_product_class AS prdcls";
422            $where = "product_id = ?";
423            $objQuery->setorder("rank1 DESC, rank2 DESC");
424            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
425        }
426        return $arrRet;
427    }
428
429    /* 入力内容のチェック */
430    function lfCheckError($id) {
431
432        // 入力データを渡す。
433        $objErr = new SC_CheckError();
434
435        $classcategory_id1 = "classcategory_id". $id. "_1";
436        $classcategory_id2 = "classcategory_id". $id. "_2";
437        $quantity = "quantity". $id;
438        // 複数項目チェック
439        if ($this->tpl_classcat_find1[$id]) {
440            $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
441        }
442        if ($this->tpl_classcat_find2[$id]) {
443            $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
444        }
445        $objErr->doFunc(array("個数", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
446
447        return $objErr->arrErr;
448    }
449
450    // 購入制限数の設定
451    function lfGetSaleLimit($product) {
452        //在庫が無限または購入制限値が設定値より大きい場合
453        if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) {
454            $this->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX;
455        } else {
456            $this->tpl_sale_limit[$product['product_id']] = $product['sale_limit'];
457        }
458
459        return $this;
460    }
461
462    //支払方法の取得
463    //payment_id    1:代金引換 2:銀行振り込み 3:現金書留
464    function lfGetPayment() {
465        $objQuery = new SC_Query;
466        $col = "payment_id, rule, payment_method";
467        $from = "dtb_payment";
468        $where = "del_flg = 0";
469        $order = "payment_id";
470        $objQuery->setorder($order);
471        $arrRet = $objQuery->select($col, $from, $where);
472        return $arrRet;
473    }
474
475    function lfconvertParam () {
476        foreach ($this->arrForm as $key => $value) {
477            if (preg_match('/^quantity[0-9]+/', $key)) {
478                 $this->arrForm[$key]
479                    = htmlspecialchars($this->arrForm[$key], ENT_QUOTES, CHAR_CODE);
480            }
481        }
482    }
483}
484?>
Note: See TracBrowser for help on using the repository browser.