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

Revision 20116, 17.5 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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_REALDIR . "pages/LC_Page.php");
26
27/**
28 * 商品一覧 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
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     * Page のAction.
93     *
94     * @return void
95     */
96    function action() {
97        $this->lfLoadParam();
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
169                // カート「戻るボタン」用に保持
170                if (SC_Utils_Ex::sfIsInternalDomain($_SERVER['HTTP_REFERER'])) {
171                    $_SESSION['cart_referer_url'] = $_SERVER['HTTP_REFERER'];
172                }
173
174                SC_Response_Ex::sendRedirect(CART_URLPATH);
175                exit;
176            }
177            foreach (array_keys($this->arrProducts) as $key) {
178                $arrProduct =& $this->arrProducts[$key];
179                if ($arrProduct['product_id'] == $product_id) {
180                    $arrProduct['product_class_id'] = $this->arrForm['product_class_id'];
181                    $arrProduct['classcategory_id1'] = $this->arrForm['classcategory_id1'];
182                    $arrProduct['classcategory_id2'] = $this->arrForm['classcategory_id2'];
183                    $arrProduct['quantity'] = $this->arrForm['quantity'];
184                    $arrProduct['arrErr'] = $arrErr;
185                    $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']}, '{$this->arrForm['classcategory_id2']}');\n";
186                }
187            }
188        }
189
190        // ページャ用データ設定(モバイル)
191        if (Net_UserAgent_Mobile::isMobile() === true) {
192            $this->lfSetPagerMobile();
193        }
194
195        $this->tpl_javascript .= 'function fnOnLoad(){' . $js_fnOnLoad . '}';
196        $this->tpl_onload .= 'fnOnLoad(); ';
197
198        $this->tpl_rnd = SC_Utils_Ex::sfGetRandomString(3);
199    }
200
201    /**
202     * デストラクタ.
203     *
204     * @return void
205     */
206    function destroy() {
207        parent::destroy();
208    }
209
210    /**
211     * カテゴリIDの取得
212     *
213     * @return integer カテゴリID
214     */
215    function lfGetCategoryId($category_id) {
216        $objDb = new SC_Helper_DB_Ex();
217
218        // 指定なしの場合、0 を返す
219        if (
220            strlen($category_id) == 0
221            || (String) $category_id == '0'
222        ) {
223            return 0;
224        }
225
226        // 正当性チェック
227        if (
228            !SC_Utils_Ex::sfIsInt($category_id)
229                || SC_Utils_Ex::sfIsZeroFilling($category_id)
230            || !$objDb->sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')
231        ) {
232            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
233    }
234
235        // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。
236        $arrCategory_id = $objDb->sfGetCategoryId('', $category_id);
237
238        if (empty($arrCategory_id)) {
239            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
240        }
241
242        return $arrCategory_id[0];
243    }
244
245    /* 商品一覧の表示 */
246    function lfDispProductsList() {
247        $objDb = new SC_Helper_DB_Ex();
248        $arrval = array();
249        $arrval_order = array();
250        $arrval_category = array();
251
252        // カテゴリからのWHERE文字列取得
253        if ($this->arrSearchData['category_id'] != 0) {
254            list($where_category, $arrval_category) = $objDb->sfGetCatWhere($this->arrSearchData['category_id']);
255        }
256        // ▼対象商品IDの抽出
257        // 商品検索条件の作成(未削除、表示)
258        $where = "alldtl.del_flg = 0 AND alldtl.status = 1 ";
259
260        // 在庫無し商品の非表示
261        if (NOSTOCK_HIDDEN === true) {
262            $where .= ' AND (stock >= 1 OR stock_unlimited = 1)';
263        }
264
265        if (strlen($where_category) >= 1) {
266            $where .= " AND T2.$where_category";
267            $arrval = array_merge($arrval, $arrval_category);
268        }
269
270        // 商品名をwhere文に
271        $name = $this->arrSearchData['name'];
272        $name = ereg_replace(",", "", $name);// XXX
273        // 全角スペースを半角スペースに変換
274        $name = str_replace(' ', ' ', $name);
275        // スペースでキーワードを分割
276        $names = preg_split("/ +/", $name);
277        // 分割したキーワードを一つずつwhere文に追加
278        foreach ($names as $val) {
279            if ( strlen($val) > 0 ) {
280                $where .= " AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) ";
281                $arrval[] = "%$val%";
282                $arrval[] = "%$val%";
283            }
284        }
285
286        // メーカーらのWHERE文字列取得
287        if ($this->arrSearchData['maker_id']) {
288            $where .= " AND alldtl.maker_id = ? ";
289            $arrval[] = $this->arrSearchData['maker_id'];
290        }
291
292        // 検索結果対象となる商品の数を取得
293        $objQuery =& SC_Query::getSingletonInstance();
294        $objQuery->setWhere($where);
295        $objProduct = new SC_Product();
296        $linemax = $objProduct->findProductCount($objQuery, $arrval);
297        $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用
298
299        // ページ送りの取得
300        $urlParam = "category_id={$this->arrSearchData['category_id']}&pageno=#page#";
301        $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $this->disp_number, "fnNaviPage", NAVI_PMAX, $urlParam);
302        $strnavi = $this->objNavi->strnavi;
303
304        // 表示文字列
305        $this->tpl_strnavi = empty($strnavi) ? "&nbsp;" : $strnavi;
306        $startno = $this->objNavi->start_row;                 // 開始行
307
308        $objProduct = new SC_Product();
309        $objQuery =& SC_Query::getSingletonInstance();
310        // 表示順序
311        switch ($this->orderby) {
312            // 販売価格が安い順
313            case 'price':
314                $objProduct->setProductsOrder('price02', 'dtb_products_class', 'ASC');
315                break;
316
317            // 新着順
318            case 'date':
319                $objProduct->setProductsOrder('create_date', 'dtb_products', 'DESC');
320                break;
321
322            default:
323                if (strlen($where_category) >= 1) {
324                    $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE $where_category)";
325                    $arrval_order = array_merge($arrval_category, $arrval_category);
326                } else {
327                    $dtb_product_categories = 'dtb_product_categories';
328                }
329                $order = <<< __EOS__
330                    (
331                        SELECT
332                             T3.rank
333                        FROM
334                            $dtb_product_categories T2
335                            JOIN dtb_category T3
336                                USING (category_id)
337                        WHERE T2.product_id = alldtl.product_id
338                        ORDER BY T3.rank DESC, T2.rank DESC
339                        LIMIT 1
340                    ) DESC
341                    ,(
342                        SELECT
343                            T2.rank
344                        FROM
345                            $dtb_product_categories T2
346                            JOIN dtb_category T3
347                                USING (category_id)
348                        WHERE T2.product_id = alldtl.product_id
349                        ORDER BY T3.rank DESC, T2.rank DESC
350                        LIMIT 1
351                    ) DESC
352                    ,product_id
353__EOS__;
354                    $objQuery->setOrder($order);
355                break;
356        }
357        // 取得範囲の指定(開始行番号、行数のセット)
358        $objQuery->setLimitOffset($this->disp_number, $startno);
359        $objQuery->setWhere($where);
360
361         // 表示すべきIDとそのIDの並び順を一気に取得
362        $arrProduct_id = $objProduct->findProductIdsOrder($objQuery, array_merge($arrval, $arrval_order));
363
364        // 取得した表示すべきIDだけを指定して情報を取得。
365        $where = "";
366        if (is_array($arrProduct_id) && !empty($arrProduct_id)) {
367            $where = 'product_id IN (' . implode(',', $arrProduct_id) . ')';
368        } else {
369            // 一致させない
370            $where = '0<>0';
371        }
372        $objQuery =& SC_Query::getSingletonInstance();
373        $objQuery->setWhere($where);
374        $arrProducts = $objProduct->lists($objQuery, $arrProduct_id);
375
376        //取得している並び順で並び替え
377        $arrProducts2 = array();
378        foreach($arrProducts as $item) {
379            $arrProducts2[ $item['product_id'] ] = $item;
380        }
381        $this->arrProducts = array();
382        foreach($arrProduct_id as $product_id) {
383            $this->arrProducts[] = $arrProducts2[$product_id];
384        }
385
386        // 規格を設定
387        $objProduct->setProductsClassByProductIds($arrProduct_id);
388
389        // 規格1クラス名
390        $this->tpl_class_name1 = $objProduct->className1;
391
392        // 規格2クラス名
393        $this->tpl_class_name2 = $objProduct->className2;
394
395        // 規格1
396        $this->arrClassCat1 = $objProduct->classCats1;
397
398        // 規格1が設定されている
399        $this->tpl_classcat_find1 = $objProduct->classCat1_find;
400        // 規格2が設定されている
401        $this->tpl_classcat_find2 = $objProduct->classCat2_find;
402
403        $this->tpl_stock_find = $objProduct->stock_find;
404        $this->tpl_product_class_id = $objProduct->product_class_id;
405        $this->tpl_product_type = $objProduct->product_type;
406
407        // 商品ステータスを取得
408        $this->productStatus = $objProduct->getProductStatus($arrProduct_id);
409
410        $productsClassCategories = $objProduct->classCategories;
411
412        $objJson = new Services_JSON();
413        $this->tpl_javascript .= 'productsClassCategories = ' . $objJson->encode($productsClassCategories) . '; ';
414    }
415
416    /* 入力内容のチェック */
417    function lfCheckError($id) {
418
419        // 入力データを渡す。
420        $objErr = new SC_CheckError($this->arrForm);
421
422        // 複数項目チェック
423        if ($this->tpl_classcat_find1[$id]) {
424            $objErr->doFunc(array("規格1", 'classcategory_id1', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
425        }
426        if ($this->tpl_classcat_find2[$id]) {
427            $objErr->doFunc(array("規格2", 'classcategory_id2', INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
428        }
429        $objErr->doFunc(array("数量", 'quantity', INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
430
431        return $objErr->arrErr;
432    }
433
434    /**
435     * パラメータの読み込み
436     *
437     * @return void
438     */
439    function lfLoadParam() {
440        $this->arrForm = $_GET;
441
442        $this->mode = $this->getMode();
443        $this->arrSearchData['category_id'] = $this->lfGetCategoryId($this->arrForm['category_id']);
444        $this->arrSearchData['maker_id'] = $this->arrForm['maker_id'];
445        $this->arrSearchData['name'] = $this->arrForm['name'];
446        $this->orderby = $this->arrForm['orderby'];
447        // 表示件数
448        if (
449            isset($this->arrForm['disp_number'])
450            && SC_Utils_Ex::sfIsInt($this->arrForm['disp_number'])
451        ) {
452            $this->disp_number = $this->arrForm['disp_number'];
453        } else {
454            //最小表示件数を選択
455            $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX));
456        }
457        $this->tpl_pageno = $this->arrForm['pageno'];
458        $this->inCart = strlen($this->arrForm['product_id']) >= 1;
459    }
460
461    /**
462     * ページャ用データ設定(モバイル)
463     *
464     * @return void
465     */
466    function lfSetPagerMobile() {
467        // ページ送り機能用のURLを作成する。
468        $objURL = new Net_URL($_SERVER['PHP_SELF']);
469        foreach ($_REQUEST as $key => $value) {
470            if ($key == session_name() || $key == 'pageno') {
471                continue;
472            }
473            $objURL->addQueryString($key, mb_convert_encoding($value, 'SJIS', CHAR_CODE));
474        }
475
476        if ($this->objNavi->now_page > 1) {
477            $objURL->addQueryString('pageno', $this->objNavi->now_page - 1);
478            $this->tpl_previous_page = $objURL->path . '?' . $objURL->getQueryString();
479        }
480        if ($this->objNavi->now_page < $this->objNavi->max_page) {
481            $objURL->addQueryString('pageno', $this->objNavi->now_page + 1);
482            $this->tpl_next_page = $objURL->path . '?' . $objURL->getQueryString();
483        }
484    }
485}
486?>
Note: See TracBrowser for help on using the repository browser.