source: branches/version-2_5-dev/data/class/pages/products/LC_Page_Products_List.php @ 18792

Revision 18792, 19.0 KB checked in by nanasess, 14 years ago (diff)

r18789 の変更に伴い SC_Utils::sfManualEscape() が不具合を発生していたので, 使用しないように修正(#801)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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:LC_Page_Products_List.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Products_List extends LC_Page {
35
36    // {{{ properties
37
38    /** テンプレートクラス名1 */
39    var $tpl_class_name1 = array();
40
41    /** テンプレートクラス名2 */
42    var $tpl_class_name2 = array();
43
44    /** JavaScript テンプレート */
45    var $tpl_javascript;
46
47    var $orderby;
48
49    var $mode;
50
51    /** 検索条件(内部データ) */
52    var $arrSearchData = array();
53
54    /** 検索条件(表示用) */
55    var $arrSearch = array();
56
57    var $tpl_subtitle = '';
58
59    /** ランダム文字列 **/
60    var $tpl_rnd = '';
61
62    // }}}
63    // {{{ functions
64
65    /**
66     * Page を初期化する.
67     *
68     * @return void
69     */
70    function init() {
71        parent::init();
72
73        $masterData = new SC_DB_MasterData_Ex();
74        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
75        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
76        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
77        $this->arrPRODUCTLISTMAX = $masterData->getMasterData("mtb_product_list_max");
78    }
79
80    /**
81     * Page のプロセス.
82     *
83     * @return void
84     */
85    function process() {
86        $this->lfLoadParam();
87
88        $objView = new SC_SiteView(!$this->inCart);
89        $objQuery = new SC_Query();
90        $objDb = new SC_Helper_DB_Ex();
91
92        // タイトル編集
93        if ($this->mode == 'search') {
94            $this->tpl_subtitle = "検索結果";
95        } elseif ($this->arrSearchData['category_id'] == 0) {
96            $this->tpl_subtitle = "全商品";
97        } else {
98            $arrCat = $objDb->sfGetCat($this->arrSearchData['category_id']);
99            $this->tpl_subtitle = $arrCat['name'];
100        }
101
102        $count = $objQuery->count("dtb_best_products", "category_id = ?", array($this->arrSearchData['category_id']));
103
104        // 商品一覧の表示処理
105        $this->lfDispProductsList();
106
107        // 検索条件を画面に表示
108        // カテゴリー検索条件
109        if ($this->arrSearchData['category_id'] == 0) {
110            $this->arrSearch['category'] = "指定なし";
111        } else {
112            $arrCat = $objQuery->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?", array($this->arrSearchData['category_id']));
113            $this->arrSearch['category'] = $arrCat;
114        }
115
116        // メーカー検索条件
117        if (strlen($this->arrSearchData['maker_id']) == 0) {
118            $this->arrSearch['maker'] = "指定なし";
119        } else {
120            $this->arrSearch['maker'] = $objQuery->getOne("SELECT name FROM dtb_maker WHERE maker_id = ?", $this->arrSearchData['maker_id']);
121        }
122
123        // 商品名検索条件
124        if (strlen($this->arrSearchData['name']) == 0) {
125            $this->arrSearch['name'] = "指定なし";
126        } else {
127            $this->arrSearch['name'] = $this->arrSearchData['name'];
128        }
129
130        // レイアウトデザインを取得
131        $layout = new SC_Helper_PageLayout_Ex();
132        $layout->sfGetPageLayout($this, false, "products/list.php");
133
134        foreach ($this->arrProducts as $arrProduct) {
135            $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});\n";
136        }
137       
138        if ($this->inCart) {
139            // 商品IDの正当性チェック
140            if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $this->arrForm['product_id'], "del_flg = 0 AND status = 1")) {
141                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
142            }
143            $product_id = $this->arrForm['product_id'];
144            // 入力内容のチェック
145            $arrErr = $this->lfCheckError($product_id);
146            if (count($arrErr) == 0) {
147                $classcategory_id1 = $this->arrForm['classcategory_id1'];
148                $classcategory_id2 = $this->arrForm['classcategory_id2'];
149                    // 規格1が設定されていない場合
150                if (!$this->tpl_classcat_find1[$product_id]) {
151                        $classcategory_id1 = '0';
152                    }
153                    // 規格2が設定されていない場合
154                if (!$this->tpl_classcat_find2[$product_id]) {
155                        $classcategory_id2 = '0';
156                    }
157                $objCartSess = new SC_CartSession();
158                $objCartSess->addProduct(array($product_id, $classcategory_id1, $classcategory_id2), $this->arrForm['quantity']);
159                    $this->sendRedirect($this->getLocation(URL_CART_TOP));
160                    exit;
161            }
162            foreach (array_keys($this->arrProducts) as $key) {
163                $arrProduct =& $this->arrProducts[$key];
164                if ($arrProduct['product_id'] == $product_id) {
165                    $arrProduct['classcategory_id1'] = $this->arrForm['classcategory_id1'];
166                    $arrProduct['classcategory_id2'] = $this->arrForm['classcategory_id2'];
167                    $arrProduct['quantity'] = $this->arrForm['quantity'];
168                    $arrProduct['arrErr'] = $arrErr;
169                    $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']}, '{$this->arrForm['classcategory_id2']}');\n";
170                }
171            }
172        }
173        $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}';
174        $this->tpl_onload .= 'fnOnLoad(); ';
175
176        $this->tpl_rnd = SC_Utils_Ex::sfGetRandomString(3);
177
178        $objView->assignobj($this);
179        $objView->display(SITE_FRAME);
180    }
181
182    /**
183     * モバイルページを初期化する.
184     *
185     * @return void
186     */
187    function mobileInit() {
188        $this->init();
189    }
190
191    /**
192     * Page のプロセス(モバイル).
193     *
194     * FIXME スパゲッティ...
195     *
196     * @return void
197     */
198    function mobileProcess() {
199        $this->lfLoadParam();
200
201        $objView = new SC_MobileView();
202        $objQuery = new SC_Query();
203        $objDb = new SC_Helper_DB_Ex();
204
205        // タイトル編集
206        $tpl_search_mode = false;
207
208        if ($this->mode == 'search') {
209            $this->tpl_subtitle = "検索結果";
210            $tpl_search_mode = true;
211        } elseif ($this->arrSearchData['category_id'] == 0) {
212            $this->tpl_subtitle = "全商品";
213        } else {
214            $arrCat = $objDb->sfGetCat($this->arrSearchData['category_id']);
215            $this->tpl_subtitle = $arrCat['name'];
216        }
217
218        $count = $objQuery->count("dtb_best_products", "category_id = ?", array($this->arrSearchData['category_id']));
219
220            // 商品一覧の表示処理
221        $this->lfDispProductsList();
222
223            // 検索条件を画面に表示
224            // カテゴリー検索条件
225        if ($this->arrSearchData['category_id'] == 0) {
226            $this->arrSearch['category'] = "指定なし";
227        } else {
228                $arrCat = $objQuery->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id));
229            $this->arrSearch['category'] = $arrCat;
230            }
231
232            // 商品名検索条件
233        if ($this->arrForm['name'] === "") {
234            $this->arrSearch['name'] = "指定なし";
235            } else {
236            $this->arrSearch['name'] = $this->arrForm['name'];
237                    }
238
239        // ページ送り機能用のURLを作成する。
240        $objURL = new Net_URL($_SERVER['PHP_SELF']);
241        foreach ($_REQUEST as $key => $value) {
242            if ($key == session_name() || $key == 'pageno') {
243                continue;
244            }
245            $objURL->addQueryString($key, mb_convert_encoding($value, 'SJIS', CHAR_CODE));
246        }
247
248        if ($this->objNavi->now_page > 1) {
249            $objURL->addQueryString('pageno', $this->objNavi->now_page - 1);
250            $this->tpl_previous_page = $objURL->path . '?' . $objURL->getQueryString();
251        }
252        if ($this->objNavi->now_page < $this->objNavi->max_page) {
253            $objURL->addQueryString('pageno', $this->objNavi->now_page + 1);
254            $this->tpl_next_page = $objURL->path . '?' . $objURL->getQueryString();
255        }
256
257        $this->tpl_search_mode = $tpl_search_mode;
258
259        $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "products/list.tpl";
260
261        $objView->assignobj($this);
262        $objView->display(SITE_FRAME);
263    }
264
265    /**
266     * デストラクタ.
267     *
268     * @return void
269     */
270    function destroy() {
271        parent::destroy();
272    }
273
274    /**
275     * カテゴリIDの取得
276     *
277     * @return integer カテゴリID
278     */
279    function lfGetCategoryId($category_id) {
280        $objDb = new SC_Helper_DB_Ex();
281       
282        // 指定なしの場合、0 を返す
283        if (
284            strlen($category_id) == 0
285            || (String) $category_id == '0'
286        ) {
287            return 0;
288        }
289       
290        // 正当性チェック
291        if (
292            !SC_Utils_Ex::sfIsInt($category_id)
293                || SC_Utils_Ex::sfIsZeroFilling($category_id)
294            || !$objDb->sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')
295        ) {
296            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
297    }
298       
299        // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。
300        $arrCategory_id = $objDb->sfGetCategoryId('', $category_id);
301       
302        if (empty($arrCategory_id)) {
303            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
304        }
305       
306        return $arrCategory_id[0];
307    }
308
309    /* 商品一覧の表示 */
310    function lfDispProductsList() {
311
312        $objQuery = new SC_Query();
313        $objDb = new SC_Helper_DB_Ex();
314        $arrval = array();
315        $arrval_order = array();
316        $arrval_category = array();
317       
318        // カテゴリからのWHERE文字列取得
319        if ($this->arrSearchData['category_id'] != 0) {
320            list($where_category, $arrval_category) = $objDb->sfGetCatWhere($this->arrSearchData['category_id']);
321        }
322       
323        // ▼対象商品IDの抽出
324        // 商品検索条件の作成(未削除、表示)
325        $where = "del_flg = 0 AND status = 1 ";
326       
327        // 在庫無し商品の非表示
328        if (NOSTOCK_HIDDEN === true) {
329            $where .= ' AND (stock_max >= 1 OR stock_unlimited_max = 1)';
330        }
331       
332        if (strlen($where_category) >= 1) {
333            $where.= " AND $where_category";
334            $arrval = array_merge($arrval, $arrval_category);
335        }
336
337        // 商品名をwhere文に
338        $name = $this->arrSearchData['name'];
339        $name = ereg_replace(",", "", $name);// XXX
340        // 全角スペースを半角スペースに変換
341        $name = str_replace(' ', ' ', $name);
342        // スペースでキーワードを分割
343        $names = preg_split("/ +/", $name);
344        // 分割したキーワードを一つずつwhere文に追加
345        foreach ($names as $val) {
346            if ( strlen($val) > 0 ) {
347                $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) ";
348                $arrval[] = "%$val%";
349                $arrval[] = "%$val%";
350            }
351        }
352
353        // メーカーらのWHERE文字列取得
354        if ($this->arrSearchData['maker_id']) {
355            $where .= " AND maker_id = ? ";
356            $arrval[] = $this->arrSearchData['maker_id'];
357        }
358       
359        // 対象商品IDの抽出
360        $arrProduct_id = array_unique($objQuery->getCol('vw_products_allclass AS allcls', 'product_id', $where, $arrval));
361        // 行数の取得
362        $linemax = count($arrProduct_id);
363
364        $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用
365
366        // ページ送りの取得
367        $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#";
368        $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam);
369        $strnavi = $this->objNavi->strnavi;
370
371        // 表示文字列
372        $this->tpl_strnavi = empty($strnavi) ? "&nbsp;" : $strnavi;
373        $startno = $this->objNavi->start_row;                 // 開始行
374       
375        // ▼商品詳細取得
376        $col = <<< __EOS__
377             product_id
378            ,product_code_min
379            ,product_code_max
380            ,name
381            ,comment1
382            ,comment2
383            ,comment3
384            ,main_list_comment
385            ,main_image
386            ,main_list_image
387            ,price01_min
388            ,price01_max
389            ,price02_min
390            ,price02_max
391            ,stock_min
392            ,stock_max
393            ,stock_unlimited_min
394            ,stock_unlimited_max
395            ,point_rate
396            ,sale_limit
397            ,deliv_date_id
398            ,deliv_fee
399            ,status
400            ,product_flag
401            ,del_flg
402__EOS__;
403       
404        $from = "vw_products_allclass_detail AS alldtl";
405       
406        // WHERE 句
407        $where = '0=0';
408        if (is_array($arrProduct_id) && !empty($arrProduct_id)) {
409            $where .= ' AND product_id IN (' . implode(',', $arrProduct_id) . ')';
410        } else {
411            // 一致させない
412            $where .= ' AND 0<>0';
413        }
414       
415        // 表示順序
416        switch ($this->orderby) {
417
418            // 販売価格順
419            case 'price':
420                $order = "price02_min, product_id";
421                break;
422
423            // 新着順
424            case 'date':
425                $order = "create_date DESC, product_id";
426                break;
427
428            default:
429                if (strlen($where_category) >= 1) {
430                    $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE $where_category)";
431                    $arrval_order = array_merge($arrval_category, $arrval_category);
432                } else {
433                    $dtb_product_categories = 'dtb_product_categories';
434                }
435                $order = <<< __EOS__
436                    (
437                        SELECT
438                             T3.rank
439                        FROM
440                            $dtb_product_categories T2
441                            JOIN dtb_category T3
442                                USING (category_id)
443                        WHERE T2.product_id = alldtl.product_id
444                        ORDER BY T3.rank DESC, T2.rank DESC
445                        LIMIT 1
446                    ) DESC
447                    ,(
448                        SELECT
449                            T2.rank
450                        FROM
451                            $dtb_product_categories T2
452                            JOIN dtb_category T3
453                                USING (category_id)
454                        WHERE T2.product_id = alldtl.product_id
455                        ORDER BY T3.rank DESC, T2.rank DESC
456                        LIMIT 1
457                    ) DESC
458                    ,product_id
459__EOS__;
460                break;
461        }
462       
463        // 取得範囲の指定(開始行番号、行数のセット)
464        $objQuery->setLimitOffset($this->disp_number, $startno);
465        // 表示順序
466        $objQuery->setOrder($order);
467       
468        // 検索結果の取得
469        $this->arrProducts = $objQuery->select($col, $from, $where, $arrval_order);
470        // ▲商品詳細取得
471       
472        $arrProductId = array();
473        // 規格セレクトボックス設定
474        foreach ($this->arrProducts as $product) {
475            $arrProductId[] = $product['product_id'];
476        }
477       
478        require_once CLASS_PATH . 'SC_Product.php';
479        $objProduct = new SC_Product($arrProductId);
480       
481        // 規格1クラス名
482        $this->tpl_class_name1 = $objProduct->className1;
483
484        // 規格2クラス名
485        $this->tpl_class_name2 = $objProduct->className2;
486       
487        // 規格1
488        $this->arrClassCat1 = $objProduct->classCats1;
489
490        // 規格1が設定されている
491        $this->tpl_classcat_find1 = $objProduct->classCat1_find;
492        // 規格2が設定されている
493        $this->tpl_classcat_find2 = $objProduct->classCat2_find;
494
495        $this->tpl_stock_find = $objProduct->stock_find;
496
497        $productsClassCategories = $objProduct->classCategories;
498       
499        require_once DATA_PATH . 'module/Services/JSON.php';
500        $objJson = new Services_JSON();
501        $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($productsClassCategories) . '; ';
502    }
503
504    /* 入力内容のチェック */
505    function lfCheckError($id) {
506
507        // 入力データを渡す。
508        $objErr = new SC_CheckError($this->arrForm);
509
510        // 複数項目チェック
511        if ($this->tpl_classcat_find1[$id]) {
512            $objErr->doFunc(array("規格1", 'classcategory_id1', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
513        }
514        if ($this->tpl_classcat_find2[$id]) {
515            $objErr->doFunc(array("規格2", 'classcategory_id2', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
516        }
517        $objErr->doFunc(array("数量", 'quantity', INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
518
519        return $objErr->arrErr;
520    }
521
522    /**
523     * パラメータの読み込み
524     *
525     * @return void
526     */
527    function lfLoadParam() {
528        $this->arrForm = $_GET;
529       
530        $this->mode = $this->arrForm['mode'];
531        $this->arrSearchData['category_id'] = $this->lfGetCategoryId($this->arrForm['category_id']);
532        $this->arrSearchData['maker_id'] = $this->arrForm['maker_id'];
533        $this->arrSearchData['name'] = $this->arrForm['name'];
534        $this->orderby = $this->arrForm['orderby'];
535        // 表示件数
536        if (
537            isset($this->arrForm['disp_number'])
538            && SC_Utils_Ex::sfIsInt($this->arrForm['disp_number'])
539        ) {
540            $this->disp_number = $this->arrForm['disp_number'];
541        } else {
542            //最小表示件数を選択
543            $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX));
544        }
545        $this->tpl_pageno = $this->arrForm['pageno'];
546        $this->inCart = strlen($this->arrForm['product_id']) >= 1;
547    }
548}
549?>
Note: See TracBrowser for help on using the repository browser.