source: branches/version-2_12-multilang/data/class/pages/products/LC_Page_Products_List.php @ 22408

Revision 22408, 19.8 KB checked in by kim, 11 years ago (diff)

#2060 メッセージIDの振り直し SC_Fpdf_001-002(002とPARAM_LABEL_QUANTITY、LC_Page_Admin_Total_024を統合)
#2060 メッセージIDの振り直し SC_Fpdf003とLC_Page_Admin_Total_025、PARAM_LABEL_PRICEを統合
#2060 メッセージIDの振り直し SC_Fpdf004-006(006とPARAM_LABEL_DELIV_FEEを統合)
#2060 メッセージIDの振り直し SC_Fpdf007とPARAM_LABEL_CHARGE統合、SC_CartSession_001を修正時の間違いを訂正

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