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

Revision 20449, 22.5 KB checked in by shutta, 13 years ago (diff)

SC_Sessionクラスのclass_extends対応。

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