Warning: Can't use blame annotator:
svn blame failed on branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_List.php: バイナリファイル 'file:///home/svn/open/branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_List.php' に対しては blame で各行の最終変更者を計算できません 195004

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

Revision 22946, 21.4 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
不要な変数を削除
ソースの整形

  • 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
RevLine 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * 商品一覧 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Products_List extends LC_Page_Ex
34{
35    /** テンプレートクラス名1 */
36    var $tpl_class_name1 = array();
37
38    /** テンプレートクラス名2 */
39    var $tpl_class_name2 = array();
40
41    /** JavaScript テンプレート */
42    var $tpl_javascript;
43
44    var $orderby;
45
46    var $mode;
47
48    /** 検索条件(内部データ) */
49    var $arrSearchData = array();
50
51    /** 検索条件(表示用) */
52    var $arrSearch = array();
53
54    var $tpl_subtitle = '';
55
56    /** ランダム文字列 **/
57    var $tpl_rnd = '';
58
59    /**
60     * Page を初期化する.
61     *
62     * @return void
63     */
64    function init()
65    {
66        parent::init();
67
68        $masterData                 = new SC_DB_MasterData_Ex();
69        $this->arrSTATUS            = $masterData->getMasterData('mtb_status');
70        $this->arrSTATUS_IMAGE      = $masterData->getMasterData('mtb_status_image');
71        $this->arrDELIVERYDATE      = $masterData->getMasterData('mtb_delivery_date');
72        $this->arrPRODUCTLISTMAX    = $masterData->getMasterData('mtb_product_list_max');
73    }
74
75    /**
76     * Page のプロセス.
77     *
78     * @return void
79     */
80    function process()
81    {
82        parent::process();
83        $this->action();
84        $this->sendResponse();
85    }
86
87    /**
88     * Page のAction.
89     *
90     * @return void
91     */
92    function action()
93    {
94        $objProduct = new SC_Product_Ex();
95        // パラメーター管理クラス
96        $objFormParam = new SC_FormParam_Ex();
97
98        // パラメーター情報の初期化
99        $this->lfInitParam($objFormParam);
100
101        // 値の設定
102        $objFormParam->setParam($_REQUEST);
103
104        // 入力値の変換
105        $objFormParam->convParam();
106
107        // 値の取得
108        $this->arrForm = $objFormParam->getHashArray();
109
110        //modeの取得
111        $this->mode = $this->getMode();
112
113        //表示条件の取得
114        $this->arrSearchData = array(
115            'category_id'   => $this->lfGetCategoryId(intval($this->arrForm['category_id'])),
116            'maker_id'      => intval($this->arrForm['maker_id']),
117            'name'          => $this->arrForm['name']
118        );
119        $this->orderby = $this->arrForm['orderby'];
120
121        //ページング設定
122        $this->tpl_pageno   = $this->arrForm['pageno'];
123        $this->disp_number  = $this->lfGetDisplayNum($this->arrForm['disp_number']);
124
125        // 画面に表示するサブタイトルの設定
126        $this->tpl_subtitle = $this->lfGetPageTitle($this->mode, $this->arrSearchData['category_id']);
127
128        // 画面に表示する検索条件を設定
129        $this->arrSearch    = $this->lfGetSearchConditionDisp($this->arrSearchData);
130
131        // 商品一覧データの取得
132        $arrSearchCondition = $this->lfGetSearchCondition($this->arrSearchData);
133        $this->tpl_linemax  = $this->lfGetProductAllNum($arrSearchCondition);
134        $urlParam           = "category_id={$this->arrSearchData['category_id']}&pageno=#page#";
135        // モバイルの場合に検索条件をURLの引数に追加
136        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
137            $searchNameUrl = urlencode(mb_convert_encoding($this->arrSearchData['name'], 'SJIS-win', 'UTF-8'));
138            $urlParam .= "&mode={$this->mode}&name={$searchNameUrl}&orderby={$this->orderby}";
139        }
140        $this->objNavi      = new SC_PageNavi_Ex($this->tpl_pageno, $this->tpl_linemax, $this->disp_number, 'fnNaviPage', NAVI_PMAX, $urlParam, SC_Display_Ex::detectDevice() !== DEVICE_TYPE_MOBILE);
141        $this->arrProducts  = $this->lfGetProductsList($arrSearchCondition, $this->disp_number, $this->objNavi->start_row, $objProduct);
142
143        switch ($this->getMode()) {
144            case 'json':
145                $this->doJson($objProduct);
146                break;
147
148            default:
149                $this->doDefault($objProduct, $objFormParam);
150                break;
151        }
152
153        $this->tpl_rnd = SC_Utils_Ex::sfGetRandomString(3);
154    }
155
156    /**
157     * パラメーター情報の初期化
158     *
159     * @param array $objFormParam フォームパラメータークラス
160     * @return void
161     */
162    function lfInitParam(&$objFormParam)
163    {
164        // 抽出条件
165        // XXX カートインしていない場合、チェックしていない
166        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
167        $objFormParam->addParam('メーカーID', 'maker_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
168        $objFormParam->addParam('商品名', 'name', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
169        $objFormParam->addParam('表示順序', 'orderby', STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
170        $objFormParam->addParam('ページ番号', 'pageno', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
171        $objFormParam->addParam('表示件数', 'disp_number', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
172        // カートイン
173        $objFormParam->addParam('規格1', 'classcategory_id1', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
174        $objFormParam->addParam('規格2', 'classcategory_id2', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
175        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
176        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
177        $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
178    }
179
180    /**
181     * カテゴリIDの取得
182     *
183     * @return integer カテゴリID
184     */
185    function lfGetCategoryId($category_id)
186    {
187        // 指定なしの場合、0 を返す
188        if (empty($category_id)) return 0;
189
190        // 正当性チェック
191        if (!SC_Utils_Ex::sfIsInt($category_id)
192            || SC_Utils_Ex::sfIsZeroFilling($category_id)
193            || !SC_Helper_DB_Ex::sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')
194            ) {
195            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
196        }
197
198        // 指定されたカテゴリIDを元に正しいカテゴリIDを取得する。
199        $arrCategory_id = SC_Helper_DB_Ex::sfGetCategoryId('', $category_id);
200
201        if (empty($arrCategory_id)) {
202            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
203        }
204
205        return $arrCategory_id[0];
206    }
207
208    /* 商品一覧の表示 */
209    function lfGetProductsList($searchCondition, $disp_number, $startno, &$objProduct)
210    {
211        $arrOrderVal = array();
212
213        $objQuery =& SC_Query_Ex::getSingletonInstance();
214        // 表示順序
215        switch ($this->orderby) {
216            // 販売価格が安い順
217            case 'price':
218                $objProduct->setProductsOrder('price02', 'dtb_products_class', 'ASC');
219                break;
220
221            // 新着順
222            case 'date':
223                $objProduct->setProductsOrder('create_date', 'dtb_products', 'DESC');
224                break;
225
226            default:
227                if (strlen($searchCondition['where_category']) >= 1) {
228                    $dtb_product_categories = '(SELECT * FROM dtb_product_categories WHERE '.$searchCondition['where_category'].')';
229                    $arrOrderVal           = $searchCondition['arrvalCategory'];
230                } else {
231                    $dtb_product_categories = 'dtb_product_categories';
232                }
233                $order = <<< __EOS__
234                    (
235                        SELECT
236                            T3.rank * 2147483648 + T2.rank
237                        FROM
238                            $dtb_product_categories T2
239                            JOIN dtb_category T3
240                              ON T2.category_id = T3.category_id
241                        WHERE T2.product_id = alldtl.product_id
242                        ORDER BY T3.rank DESC, T2.rank DESC
243                        LIMIT 1
244                    ) DESC
245                    ,product_id DESC
246__EOS__;
247                $objQuery->setOrder($order);
248                break;
249        }
250        // 取得範囲の指定(開始行番号、行数のセット)
251        $objQuery->setLimitOffset($disp_number, $startno);
252        $objQuery->setWhere($searchCondition['where']);
253
254        // 表示すべきIDとそのIDの並び順を一気に取得
255        $arrProductId = $objProduct->findProductIdsOrder($objQuery, array_merge($searchCondition['arrval'], $arrOrderVal));
256
257        $objQuery =& SC_Query_Ex::getSingletonInstance();
258        $arrProducts = $objProduct->getListByProductIds($objQuery, $arrProductId);
259
260        // 規格を設定
261        $objProduct->setProductsClassByProductIds($arrProductId);
262        $arrProducts['productStatus'] = $objProduct->getProductStatus($arrProductId);
263
264        return $arrProducts;
265    }
266
267    /* 入力内容のチェック */
268    function lfCheckError($objFormParam)
269    {
270        // 入力データを渡す。
271        $arrForm =  $objFormParam->getHashArray();
272        $objErr = new SC_CheckError_Ex($arrForm);
273        $objErr->arrErr = $objFormParam->checkError();
274
275        // 動的チェック
276        if ($this->tpl_classcat_find1[$arrForm['product_id']]) {
277            $objErr->doFunc(array('規格1', 'classcategory_id1'), array('EXIST_CHECK'));
278        }
279        if ($this->tpl_classcat_find2[$arrForm['product_id']]) {
280            $objErr->doFunc(array('規格2', 'classcategory_id2'), array('EXIST_CHECK'));
281        }
282
283        return $objErr->arrErr;
284    }
285
286    /**
287     * パラメーターの読み込み
288     *
289     * @return void
290     */
291    function lfGetDisplayNum($display_number)
292    {
293        // 表示件数
294        return (SC_Utils_Ex::sfIsInt($display_number))
295            ? $display_number
296            : current(array_keys($this->arrPRODUCTLISTMAX));
297    }
298
299    /**
300     * ページタイトルの設定
301     *
302     * @return str
303     */
304    function lfGetPageTitle($mode, $category_id = 0)
305    {
306        if ($mode == 'search') {
307            return '検索結果';
308        } elseif ($category_id == 0) {
309            return '全商品';
310        } else {
311            $objCategory = new SC_Helper_Category_Ex();
312            $arrCat = $objCategory->get($category_id);
313            return $arrCat['category_name'];
314        }
315    }
316
317    /**
318     * 表示用検索条件の設定
319     *
320     * @return array
321     */
322    function lfGetSearchConditionDisp($arrSearchData)
323    {
324        $objQuery   =& SC_Query_Ex::getSingletonInstance();
325        $arrSearch  = array('category' => '指定なし', 'maker' => '指定なし', 'name' => '指定なし');
326        // カテゴリ検索条件
327        if ($arrSearchData['category_id'] > 0) {
328            $arrSearch['category']  = $objQuery->get('category_name', 'dtb_category', 'category_id = ?', array($arrSearchData['category_id']));
329        }
330
331        // メーカー検索条件
332        if (strlen($arrSearchData['maker_id']) > 0) {
333            $objMaker = new SC_Helper_Maker_Ex();
334            $maker = $objMaker->getMaker($arrSearchData['maker_id']);
335            $arrSearch['maker']     = $maker['name'];
336        }
337
338        // 商品名検索条件
339        if (strlen($arrSearchData['name']) > 0) {
340            $arrSearch['name']      = $arrSearchData['name'];
341        }
342
343        return $arrSearch;
344    }
345
346    /**
347     * 該当件数の取得
348     *
349     * @return int
350     */
351    function lfGetProductAllNum($searchCondition)
352    {
353        // 検索結果対象となる商品の数を取得
354        $objQuery   =& SC_Query_Ex::getSingletonInstance();
355        $objQuery->setWhere($searchCondition['where_for_count']);
356        $objProduct = new SC_Product_Ex();
357
358        return $objProduct->findProductCount($objQuery, $searchCondition['arrval']);
359    }
360
361    /**
362     * 検索条件のwhere文とかを取得
363     *
364     * @return array
365     */
366    function lfGetSearchCondition($arrSearchData)
367    {
368        $searchCondition = array(
369            'where'             => '',
370            'arrval'            => array(),
371            'where_category'    => '',
372            'arrvalCategory'    => array()
373        );
374
375        // カテゴリからのWHERE文字列取得
376        if ($arrSearchData['category_id'] != 0) {
377            list($searchCondition['where_category'], $searchCondition['arrvalCategory']) = SC_Helper_DB_Ex::sfGetCatWhere($arrSearchData['category_id']);
378        }
379        // ▼対象商品IDの抽出
380        // 商品検索条件の作成(未削除、表示)
381        $searchCondition['where'] = SC_Product_Ex::getProductDispConditions('alldtl');
382
383        if (strlen($searchCondition['where_category']) >= 1) {
384            $searchCondition['where'] .= ' AND EXISTS (SELECT * FROM dtb_product_categories WHERE ' . $searchCondition['where_category'] . ' AND product_id = alldtl.product_id)';
385            $searchCondition['arrval'] = array_merge($searchCondition['arrval'], $searchCondition['arrvalCategory']);
386        }
387
388        // 商品名をwhere文に
389        $name = $arrSearchData['name'];
390        $name = str_replace(',', '', $name);
391        // 全角スペースを半角スペースに変換
392        $name = str_replace(' ', ' ', $name);
393        // スペースでキーワードを分割
394        $names = preg_split('/ +/', $name);
395        // 分割したキーワードを一つずつwhere文に追加
396        foreach ($names as $val) {
397            if (strlen($val) > 0) {
398                $searchCondition['where']    .= ' AND ( alldtl.name ILIKE ? OR alldtl.comment3 ILIKE ?) ';
399                $searchCondition['arrval'][]  = "%$val%";
400                $searchCondition['arrval'][]  = "%$val%";
401            }
402        }
403
404        // メーカーらのWHERE文字列取得
405        if ($arrSearchData['maker_id']) {
406            $searchCondition['where']   .= ' AND alldtl.maker_id = ? ';
407            $searchCondition['arrval'][] = $arrSearchData['maker_id'];
408        }
409
410        // 在庫無し商品の非表示
411        if (NOSTOCK_HIDDEN) {
412            $searchCondition['where'] .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = alldtl.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))';
413        }
414
415        // XXX 一時期内容が異なっていたことがあるので別要素にも格納している。
416        $searchCondition['where_for_count'] = $searchCondition['where'];
417
418        return $searchCondition;
419    }
420
421    /**
422     * カートに入れる商品情報にエラーがあったら戻す
423     *
424     * @return str
425     */
426    function lfSetSelectedData(&$arrProducts, $arrForm, $arrErr, $product_id)
427    {
428        $js_fnOnLoad = '';
429        foreach (array_keys($arrProducts) as $key) {
430            if ($arrProducts[$key]['product_id'] == $product_id) {
431                $arrProducts[$key]['product_class_id']  = $arrForm['product_class_id'];
432                $arrProducts[$key]['classcategory_id1'] = $arrForm['classcategory_id1'];
433                $arrProducts[$key]['classcategory_id2'] = $arrForm['classcategory_id2'];
434                $arrProducts[$key]['quantity']          = $arrForm['quantity'];
435                $arrProducts[$key]['arrErr']            = $arrErr;
436                $classcategory_id2 = SC_Utils_Ex::jsonEncode($arrForm['classcategory_id2']);
437                $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProducts[$key]['product_id']}, {$classcategory_id2});";
438            }
439        }
440
441        return $js_fnOnLoad;
442    }
443
444    /**
445     * カートに商品を追加
446     *
447     * @return void
448     */
449    function lfAddCart($arrForm)
450    {
451        $objCartSess = new SC_CartSession_Ex();
452
453        $product_class_id = $arrForm['product_class_id'];
454        $objCartSess->addProduct($product_class_id, $arrForm['quantity']);
455    }
456
457    /**
458     * 商品情報配列に商品ステータス情報を追加する
459     *
460     * @param Array $arrProducts 商品一覧情報
461     * @param Array $arrStatus 商品ステータス配列
462     * @param Array $arrStatusImage スタータス画像配列
463     * @return Array $arrProducts 商品一覧情報
464     */
465    function setStatusDataTo($arrProducts, $arrStatus, $arrStatusImage)
466    {
467        foreach ($arrProducts['productStatus'] as $product_id => $arrValues) {
468            for ($i = 0; $i < count($arrValues); $i++) {
469                $product_status_id = $arrValues[$i];
470                if (!empty($product_status_id)) {
471                    $arrProductStatus = array(
472                        'status_cd' => $product_status_id,
473                        'status_name' => $arrStatus[$product_status_id],
474                        'status_image' =>$arrStatusImage[$product_status_id],
475                    );
476                    $arrProducts['productStatus'][$product_id][$i] = $arrProductStatus;
477                }
478            }
479        }
480
481        return $arrProducts;
482    }
483
484    /**
485     *
486     * @return void
487     */
488    function doJson()
489    {
490        $this->arrProducts = $this->setStatusDataTo($this->arrProducts, $this->arrSTATUS, $this->arrSTATUS_IMAGE);
491        SC_Product_Ex::setPriceTaxTo($this->arrProducts);
492
493        // 一覧メイン画像の指定が無い商品のための処理
494        foreach ($this->arrProducts as $key=>$val) {
495            $this->arrProducts[$key]['main_list_image'] = SC_Utils_Ex::sfNoImageMainList($val['main_list_image']);
496        }
497
498        echo SC_Utils_Ex::jsonEncode($this->arrProducts);
499        SC_Response_Ex::actionExit();
500    }
501
502    /**
503     *
504     * @param type $objProduct
505     * @return void
506     */
507    function doDefault(&$objProduct, &$objFormParam)
508    {
509        //商品一覧の表示処理
510        $strnavi            = $this->objNavi->strnavi;
511        // 表示文字列
512        $this->tpl_strnavi  = empty($strnavi) ? '&nbsp;' : $strnavi;
513
514        // 規格1クラス名
515        $this->tpl_class_name1  = $objProduct->className1;
516
517        // 規格2クラス名
518        $this->tpl_class_name2  = $objProduct->className2;
519
520        // 規格1
521        $this->arrClassCat1     = $objProduct->classCats1;
522
523        // 規格1が設定されている
524        $this->tpl_classcat_find1 = $objProduct->classCat1_find;
525        // 規格2が設定されている
526        $this->tpl_classcat_find2 = $objProduct->classCat2_find;
527
528        $this->tpl_stock_find       = $objProduct->stock_find;
529        $this->tpl_product_class_id = $objProduct->product_class_id;
530        $this->tpl_product_type     = $objProduct->product_type;
531
532        // 商品ステータスを取得
533        $this->productStatus = $this->arrProducts['productStatus'];
534        unset($this->arrProducts['productStatus']);
535        $this->tpl_javascript .= 'var productsClassCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories) . ';';
536        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_PC) {
537            //onloadスクリプトを設定. 在庫ありの商品のみ出力する
538            foreach ($this->arrProducts as $arrProduct) {
539                if ($arrProduct['stock_unlimited_max'] || $arrProduct['stock_max'] > 0) {
540                    $js_fnOnLoad .= "fnSetClassCategories(document.product_form{$arrProduct['product_id']});";
541                }
542            }
543        }
544
545        //カート処理
546        $target_product_id = intval($this->arrForm['product_id']);
547        if ($target_product_id > 0) {
548            // 商品IDの正当性チェック
549            if (!SC_Utils_Ex::sfIsInt($this->arrForm['product_id'])
550                || !SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', $this->arrForm['product_id'], 'del_flg = 0 AND status = 1')) {
551                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
552            }
553
554            // 入力内容のチェック
555            $arrErr = $this->lfCheckError($objFormParam);
556            if (empty($arrErr)) {
557                $this->lfAddCart($this->arrForm);
558
559                // 開いているカテゴリーツリーを維持するためのパラメーター
560                $arrQueryString = array(
561                    'category_id' => $this->arrForm['category_id'],
562                );
563
564                SC_Response_Ex::sendRedirect(CART_URLPATH, $arrQueryString);
565                SC_Response_Ex::actionExit();
566            }
567            $js_fnOnLoad .= $this->lfSetSelectedData($this->arrProducts, $this->arrForm, $arrErr, $target_product_id);
568        } else {
569            // カート「戻るボタン」用に保持
570            $netURL = new Net_URL();
571            //該当メソッドが無いため、$_SESSIONに直接セット
572            $_SESSION['cart_referer_url'] = $netURL->getURL();
573        }
574
575        $this->tpl_javascript   .= 'function fnOnLoad() {' . $js_fnOnLoad . '}';
576        $this->tpl_onload       .= 'fnOnLoad(); ';
577    }
578}
Note: See TracBrowser for help on using the repository browser.