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

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