source: branches/version-2_12-dev/data/class/pages/products/LC_Page_Products_Detail.php @ 21563

Revision 21563, 22.3 KB checked in by Seasoft, 12 years ago (diff)

#1669 (変数の初期化漏れ)
#1613 (typo修正・ソース整形・ソースコメントの改善)

  • 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-2011 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
27if (file_exists(MODULE_REALDIR . 'mdl_gmopg/inc/function.php')) {
28    require_once MODULE_REALDIR . 'mdl_gmopg/inc/function.php';
29}
30/**
31 * 商品詳細 のページクラス.
32 *
33 * @package Page
34 * @author LOCKON CO.,LTD.
35 * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $
36 */
37class LC_Page_Products_Detail extends LC_Page_Ex {
38
39    /** 商品ステータス */
40    var $arrSTATUS;
41
42    /** 商品ステータス画像 */
43    var $arrSTATUS_IMAGE;
44
45    /** 発送予定日 */
46    var $arrDELIVERYDATE;
47
48    /** おすすめレベル */
49    var $arrRECOMMEND;
50
51    /** フォームパラメーター */
52    var $objFormParam;
53
54    /** アップロードファイル */
55    var $objUpFile;
56
57    /** モード */
58    var $mode;
59
60    // }}}
61    // {{{ functions
62
63    /**
64     * Page を初期化する.
65     *
66     * @return void
67     */
68    function init() {
69        parent::init();
70        $masterData = new SC_DB_MasterData_Ex();
71        $this->arrSTATUS = $masterData->getMasterData('mtb_status');
72        $this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image');
73        $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date');
74        $this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend');
75    }
76
77    /**
78     * Page のプロセス.
79     *
80     * @return void
81     */
82    function process() {
83        parent::process();
84        $this->action();
85        $this->sendResponse();
86    }
87
88    /**
89     * Page のAction.
90     *
91     * @return void
92     */
93    function action() {
94        // 会員クラス
95        $objCustomer = new SC_Customer_Ex();
96
97        // パラメーター管理クラス
98        $this->objFormParam = new SC_FormParam_Ex();
99        // パラメーター情報の初期化
100        $this->arrForm = $this->lfInitParam($this->objFormParam);
101        // ファイル管理クラス
102        $this->objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
103        // ファイル情報の初期化
104        $this->objUpFile = $this->lfInitFile($this->objUpFile);
105
106        // プロダクトIDの正当性チェック
107        $product_id = $this->lfCheckProductId($this->objFormParam->getValue('admin'),$this->objFormParam->getValue('product_id'));
108        $this->mode = $this->getMode();
109
110        $objProduct = new SC_Product_Ex();
111        $objProduct->setProductsClassByProductIds(array($product_id));
112
113        // 規格1クラス名
114        $this->tpl_class_name1 = $objProduct->className1[$product_id];
115
116        // 規格2クラス名
117        $this->tpl_class_name2 = $objProduct->className2[$product_id];
118
119        // 規格1
120        $this->arrClassCat1 = $objProduct->classCats1[$product_id];
121
122        // 規格1が設定されている
123        $this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id];
124        // 規格2が設定されている
125        $this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id];
126
127        $this->tpl_stock_find = $objProduct->stock_find[$product_id];
128        $this->tpl_product_class_id = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_class_id'];
129        $this->tpl_product_type = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_type'];
130
131        // 在庫が無い場合は、OnLoadしない。(javascriptエラー防止)
132        if ($this->tpl_stock_find) {
133            // 規格選択セレクトボックスの作成
134            $this->js_lnOnload .= $this->lfMakeSelect();
135        }
136
137        $this->tpl_javascript .= 'classCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories[$product_id]) . ';';
138        $this->tpl_javascript .= 'function lnOnLoad(){' . $this->js_lnOnload . '}';
139        $this->tpl_onload .= 'lnOnLoad();';
140
141        // モバイル用 規格選択セレクトボックスの作成
142        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
143            $this->lfMakeSelectMobile($this, $product_id,$this->objFormParam->getValue('classcategory_id1'));
144        }
145
146        // 商品IDをFORM内に保持する
147        $this->tpl_product_id = $product_id;
148
149        switch ($this->mode) {
150            case 'cart':
151                $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam,
152                                                    $this->tpl_classcat_find1,
153                                                    $this->tpl_classcat_find2);
154                if (count($this->arrErr) == 0) {
155                    $objCartSess = new SC_CartSession_Ex();
156                    $product_class_id = $this->objFormParam->getValue('product_class_id');
157
158                    $objCartSess->addProduct($product_class_id, $this->objFormParam->getValue('quantity'));
159
160                    SC_Response_Ex::sendRedirect(CART_URLPATH);
161                    exit;
162                }
163                break;
164            case 'add_favorite':
165                // ログイン中のユーザが商品をお気に入りにいれる処理
166                if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) {
167                    $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam);
168                    if (count($this->arrErr) == 0) {
169                        if (!$this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) {
170                            exit;
171                        }
172                    }
173                }
174                break;
175
176            case 'add_favorite_sphone':
177                // ログイン中のユーザが商品をお気に入りにいれる処理(スマートフォン用)
178                if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) {
179                    $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam);
180                    if (count($this->arrErr) == 0) {
181                        if ($this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) {
182                            print 'true';
183                            exit;
184                        }
185                    }
186                    print 'error';
187                    exit;
188                }
189                break;
190
191            case 'select':
192            case 'select2':
193            case 'selectItem':
194                /**
195                 * モバイルの数量指定・規格選択の際に、
196                 * $_SESSION['cart_referer_url'] を上書きさせないために、
197                 * 何もせずbreakする。
198                 */
199                break;
200
201            default:
202                // カート「戻るボタン」用に保持
203                $netURL = new Net_URL();
204                $_SESSION['cart_referer_url'] = $netURL->getURL();
205                break;
206        }
207
208        // モバイル用 ポストバック処理
209        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
210            switch ($this->mode) {
211                case 'select':
212                    // 規格1が設定されている場合
213                    if ($this->tpl_classcat_find1) {
214                        // templateの変更
215                        $this->tpl_mainpage = 'products/select_find1.tpl';
216                        break;
217                    }
218
219                    // 数量の入力を行う
220                    $this->tpl_mainpage = 'products/select_item.tpl';
221                    break;
222
223                case 'select2':
224                    $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam,$this->tpl_classcat_find1,$this->tpl_classcat_find2);
225
226                    // 規格1が設定されていて、エラーを検出した場合
227                    if ($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
228                        // templateの変更
229                        $this->tpl_mainpage = 'products/select_find1.tpl';
230                        break;
231                    }
232
233                    // 規格2が設定されている場合
234                    if ($this->tpl_classcat_find2) {
235                        $this->arrErr = array();
236
237                        $this->tpl_mainpage = 'products/select_find2.tpl';
238                        break;
239                    }
240
241                case 'selectItem':
242                    $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam,$this->tpl_classcat_find1,$this->tpl_classcat_find2);
243
244                    // 規格2が設定されていて、エラーを検出した場合
245                    if ($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
246                        // templateの変更
247                        $this->tpl_mainpage = 'products/select_find2.tpl';
248                        break;
249                    }
250
251                    $value1 = $this->objFormParam->getValue('classcategory_id1');
252                    $value2 = '#' . $this->objFormParam->getValue('classcategory_id2');
253
254                    if (strlen($value1) === 0) {
255                        $value1 = '__unselected';
256                    }
257
258                    $this->tpl_product_class_id = $objProduct->classCategories[$product_id][$value1][$value2]['product_class_id'];
259
260                    // この段階では、数量の入力チェックエラーを出させない。
261                    unset($this->arrErr['quantity']);
262
263                    // 数量の入力を行う
264                    $this->tpl_mainpage = 'products/select_item.tpl';
265                    break;
266
267                case 'cart':
268                    // この段階でエラーが出る場合は、数量の入力エラーのはず
269                    if (count($this->arrErr)) {
270                        // 数量の入力を行う
271                        $this->tpl_mainpage = 'products/select_item.tpl';
272                    }
273                    break;
274
275                default:
276                    $this->tpl_mainpage = 'products/detail.tpl';
277                    break;
278            }
279        }
280
281        // 商品詳細を取得
282        $this->arrProduct = $objProduct->getDetail($product_id);
283
284        // サブタイトルを取得
285        $this->tpl_subtitle = $this->arrProduct['name'];
286
287        // 関連カテゴリを取得
288        $this->arrRelativeCat = SC_Helper_DB_Ex::sfGetMultiCatTree($product_id);
289
290        // 商品ステータスを取得
291        $this->productStatus = $objProduct->getProductStatus($product_id);
292
293        // 画像ファイル指定がない場合の置換処理
294        $this->arrProduct['main_image']
295            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
296
297        $this->subImageFlag = $this->lfSetFile($this->objUpFile,$this->arrProduct,$this->arrFile);
298        //レビュー情報の取得
299        $this->arrReview = $this->lfGetReviewData($product_id);
300
301        //関連商品情報表示
302        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
303
304        // ログイン判定
305        if ($objCustomer->isLoginSuccess() === true) {
306            //お気に入りボタン表示
307            $this->tpl_login = true;
308            $this->is_favorite = SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($objCustomer->getValue('customer_id'), $product_id));
309        }
310
311    }
312
313    /**
314     * デストラクタ.
315     *
316     * @return void
317     */
318    function destroy() {
319        parent::destroy();
320    }
321
322    /* プロダクトIDの正当性チェック */
323    function lfCheckProductId($admin_mode,$product_id) {
324        // 管理機能からの確認の場合は、非公開の商品も表示する。
325        if (isset($admin_mode) && $admin_mode == 'on') {
326            SC_Utils_Ex::sfIsSuccess(new SC_Session_Ex());
327            $status = true;
328            $where = 'del_flg = 0';
329        } else {
330            $status = false;
331            $where = 'del_flg = 0 AND status = 1';
332        }
333
334        if(!SC_Utils_Ex::sfIsInt($product_id)
335            || SC_Utils_Ex::sfIsZeroFilling($product_id)
336            || !SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', (array)$product_id, $where))
337            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
338        return $product_id;
339    }
340
341    /* ファイル情報の初期化 */
342    function lfInitFile($objUpFile) {
343        $objUpFile->addFile('詳細-メイン画像', 'main_image', array('jpg'), IMAGE_SIZE);
344        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
345            $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE);
346        }
347        return $objUpFile;
348    }
349
350    /* 規格選択セレクトボックスの作成 */
351    function lfMakeSelect() {
352        return  'fnSetClassCategories('
353            . 'document.form1, '
354            . SC_Utils_Ex::jsonEncode($this->objFormParam->getValue('classcategory_id2'))
355            . '); ';
356    }
357
358    /* 規格選択セレクトボックスの作成(モバイル) */
359    function lfMakeSelectMobile(&$objPage, $product_id,$request_classcategory_id1) {
360
361        $classcat_find1 = false;
362        $classcat_find2 = false;
363
364        // 規格名一覧
365        $arrClassName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_class', 'class_id', 'name');
366        // 規格分類名一覧
367        $arrClassCatName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_classcategory', 'classcategory_id', 'name');
368        // 商品規格情報の取得
369        $arrProductsClass = $this->lfGetProductsClass($product_id);
370
371        // 規格1クラス名の取得
372        $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
373        // 規格2クラス名の取得
374        $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
375
376        // すべての組み合わせ数
377        $count = count($arrProductsClass);
378
379        $classcat_id1 = '';
380
381        $arrSele1 = array();
382        $arrSele2 = array();
383
384        for ($i = 0; $i < $count; $i++) {
385            // 在庫のチェック
386            if ($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
387                continue;
388            }
389
390            // 規格1のセレクトボックス用
391            if ($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']) {
392                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
393                $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
394            }
395
396            // 規格2のセレクトボックス用
397            if ($arrProductsClass[$i]['classcategory_id1'] == $request_classcategory_id1 and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
398                $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
399                $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
400            }
401        }
402
403        // 規格1
404        $objPage->arrClassCat1 = $arrSele1;
405        $objPage->arrClassCat2 = $arrSele2;
406
407        // 規格1が設定されている
408        if (isset($arrProductsClass[0]['classcategory_id1']) && $arrProductsClass[0]['classcategory_id1'] != '0') {
409            $classcat_find1 = true;
410        }
411
412        // 規格2が設定されている
413        if (isset($arrProductsClass[0]['classcategory_id2']) && $arrProductsClass[0]['classcategory_id2'] != '0') {
414            $classcat_find2 = true;
415        }
416
417        $objPage->tpl_classcat_find1 = $classcat_find1;
418        $objPage->tpl_classcat_find2 = $classcat_find2;
419    }
420
421    /* パラメーター情報の初期化 */
422    function lfInitParam(&$objFormParam) {
423        $objFormParam->addParam('規格1', 'classcategory_id1', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
424        $objFormParam->addParam('規格2', 'classcategory_id2', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
425        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
426        $objFormParam->addParam('管理者ログイン', 'admin', INT_LEN, 'a', array('ALNUM_CHECK','MAX_LENGTH_CHECK'));
427        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
428        $objFormParam->addParam('お気に入り商品ID', 'favorite_product_id', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
429        $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
430        // 値の取得
431        $objFormParam->setParam($_REQUEST);
432        // 入力値の変換
433        $objFormParam->convParam();
434        // 入力情報を渡す
435        return $objFormParam->getFormParamList();
436    }
437
438    /* 商品規格情報の取得 */
439    function lfGetProductsClass($product_id) {
440        $objProduct = new SC_Product_Ex();
441        return $objProduct->getProductsClassFullByProductId($product_id);
442    }
443
444    /* 登録済み関連商品の読み込み */
445    function lfPreGetRecommendProducts($product_id) {
446        $objProduct = new SC_Product_Ex();
447        $objQuery =& SC_Query_Ex::getSingletonInstance();
448
449        $objQuery->setOrder('rank DESC');
450        $arrRecommendData = $objQuery->select('recommend_product_id, comment', 'dtb_recommend_products', 'product_id = ?', array($product_id));
451
452        $arrRecommendProductId = array();
453        foreach ($arrRecommendData as $recommend) {
454            $arrRecommendProductId[] = $recommend['recommend_product_id'];
455        }
456
457        $objQuery =& SC_Query_Ex::getSingletonInstance();
458        $arrProducts = $objProduct->getListByProductIds($objQuery, $arrRecommendProductId);
459
460        $arrRecommend = array();
461        foreach ($arrRecommendData as $key => $arrRow) {
462            $arrRecommendData[$key] = array_merge($arrRow, $arrProducts[$arrRow['recommend_product_id']]);
463        }
464
465        return $arrRecommendData;
466    }
467
468    /* 入力内容のチェック */
469    function lfCheckError($mode,&$objFormParam,$tpl_classcat_find1 = null ,$tpl_classcat_find2 = null) {
470
471        switch ($mode) {
472        case 'add_favorite_sphone':
473        case 'add_favorite':
474            $objCustomer = new SC_Customer_Ex();
475            $objErr = new SC_CheckError_Ex();
476            $customer_id = $objCustomer->getValue('customer_id');
477            if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
478                $objErr->arrErr['add_favorite'.$favorite_product_id] = '※ この商品は既にお気に入りに追加されています。<br />';
479            }
480            break;
481        default:
482            // 入力データを渡す。
483            $arrRet =  $objFormParam->getHashArray();
484            $objErr = new SC_CheckError_Ex($arrRet);
485            $objErr->arrErr = $objFormParam->checkError();
486
487            // 複数項目チェック
488            if ($tpl_classcat_find1) {
489                $objErr->doFunc(array('規格1', 'classcategory_id1'), array('EXIST_CHECK'));
490            }
491            if ($tpl_classcat_find2) {
492                $objErr->doFunc(array('規格2', 'classcategory_id2'), array('EXIST_CHECK'));
493            }
494            break;
495        }
496
497        return $objErr->arrErr;
498    }
499
500    //商品ごとのレビュー情報を取得する
501    function lfGetReviewData($id) {
502        $objQuery =& SC_Query_Ex::getSingletonInstance();
503        //商品ごとのレビュー情報を取得する
504        $col = 'create_date, reviewer_url, reviewer_name, recommend_level, title, comment';
505        $from = 'dtb_review';
506        $where = 'del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT ' . REVIEW_REGIST_MAX;
507        $arrWhereVal = array($id);
508        $arrReview = $objQuery->select($col, $from, $where, $arrWhereVal);
509        return $arrReview;
510    }
511
512    /*
513     * ファイルの情報をセットする
514     * @return $subImageFlag
515     */
516    function lfSetFile($objUpFile,$arrProduct,&$arrFile) {
517        // DBからのデータを引き継ぐ
518        $objUpFile->setDBFileList($arrProduct);
519        // ファイル表示用配列を渡す
520        $arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH, true);
521
522        // サブ画像の有無を判定
523        $subImageFlag = false;
524        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
525            if ($arrFile['sub_image' . $i]['filepath'] != '') {
526                $subImageFlag = true;
527            }
528        }
529        return $subImageFlag;
530    }
531
532    /*
533     * お気に入り商品登録
534     * @return void
535     */
536    function lfRegistFavoriteProduct($favorite_product_id,$customer_id) {
537        // ログイン中のユーザが商品をお気に入りにいれる処理
538        if (!SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', $favorite_product_id, 'del_flg = 0 AND status = 1')) {
539            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
540            return false;
541        } else {
542            $objQuery =& SC_Query_Ex::getSingletonInstance();
543            $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id));
544
545            if (!$exists) {
546                $sqlval['customer_id'] = $customer_id;
547                $sqlval['product_id'] = $favorite_product_id;
548                $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
549                $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
550
551                $objQuery->begin();
552                $objQuery->insert('dtb_customer_favorite_products', $sqlval);
553                $objQuery->commit();
554            }
555            // お気に入りに登録したことを示すフラグ
556            $this->just_added_favorite = true;
557            return true;
558        }
559    }
560}
Note: See TracBrowser for help on using the repository browser.