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

Revision 21111, 21.7 KB checked in by nanasess, 13 years ago (diff)

#1425 (PC でお気に入り登録後, true と表示されてしまう)

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