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

Revision 18826, 18.7 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) カートに商品が入らない不具合修正

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