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

Revision 19803, 19.2 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

  • 一斉置換前の現状記録のためのコミット

#628(未使用処理・定義などの削除)

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