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

Revision 21285, 22.0 KB checked in by shutta, 12 years ago (diff)

refs #1508 (モバイルサイトで「お買い物を続ける」ボタンが機能しない)
モバイルの数量指定の際に、$_SESSIONcart_referer_url? を上書きしないように修正。

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