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

Revision 20344, 18.7 KB checked in by shutta, 13 years ago (diff)

LC_Pageクラスのclass_extends対応。

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