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

Revision 20408, 22.6 KB checked in by uemoto, 13 years ago (diff)

#1032(フロントデザインリニューアル)

  • CSSクラス名等調整
  • ヘッダ用ブロック追加

#932(商品をお気に入りに入れたかどうかの判別が動いていない)

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