source: branches/feature-module-update/data/class/pages/products/LC_Page_Products_Detail.php @ 15353

Revision 15353, 19.7 KB checked in by nanasess, 17 years ago (diff)

リファクタリングと未定義変数の修正

  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to application/x-httpd-php
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8// {{{ requires
9require_once(CLASS_PATH . "pages/LC_Page.php");
10
11/**
12 * 商品詳細 のページクラス.
13 *
14 * @package Page
15 * @author LOCKON CO.,LTD.
16 * @version $Id$
17 */
18class LC_Page_Products_Detail extends LC_Page {
19
20    /** ステータス */
21    var $arrSTATUS;
22
23    /** ステータス画像 */
24    var $arrSTATUS_IMAGE;
25
26    /** 発送予定日 */
27    var $arrDELIVERYDATE;
28
29    /** おすすめレベル */
30    var $arrRECOMMEND;
31
32    /** フォームパラメータ */
33    var $objFormParam;
34
35    /** アップロードファイル */
36    var $objUpFile;
37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init() {
47        parent::init();
48        $masterData = new SC_DB_MasterData_Ex();
49        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
50        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
51        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
52        $this->arrRECOMMEND = $masterData->getMasterData("mtb_recommend");
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process() {
61        $objView = new SC_SiteView();
62        $objCustomer = new SC_Customer();
63        $objQuery = new SC_Query();
64        $objDb = new SC_Helper_DB_Ex();
65
66        // レイアウトデザインを取得
67        $helper = new SC_Helper_PageLayout_Ex();
68        $this = $helper->sfGetPageLayout($this, false, "products/detail.php");
69
70        // パラメータ管理クラス
71        $this->objFormParam = new SC_FormParam();
72        // パラメータ情報の初期化
73        $this->lfInitParam();
74        // POST値の取得
75        $this->objFormParam->setParam($_POST);
76
77        // ファイル管理クラス
78        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
79        // ファイル情報の初期化
80        $this->lfInitFile();
81
82        // 管理ページからの確認の場合は、非公開の商品も表示する。
83        if(isset($_GET['admin']) && $_GET['admin'] == 'on') {
84            $where = "del_flg = 0";
85        } else {
86            $where = "del_flg = 0 AND status = 1";
87        }
88
89        if(isset($_POST['mode']) && $_POST['mode'] != "") {
90            $tmp_id = $_POST['product_id'];
91        } else {
92            $tmp_id = $_GET['product_id'];
93        }
94
95        // 値の正当性チェック
96        if(!SC_Utils_Ex::sfIsInt($_GET['product_id'])
97                || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, $where)) {
98            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
99        }
100        // ログイン判定
101        if($objCustomer->isLoginSuccess()) {
102            //お気に入りボタン表示
103            $this->tpl_login = true;
104
105        /* 閲覧ログ機能は現在未使用
106
107            $table = "dtb_customer_reading";
108            $where = "customer_id = ? ";
109            $arrval[] = $objCustomer->getValue('customer_id');
110            //顧客の閲覧商品数
111            $rpcnt = $objQuery->count($table, $where, $arrval);
112
113            //閲覧数が設定数以下
114            if ($rpcnt < CUSTOMER_READING_MAX){
115                //閲覧履歴に新規追加
116                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
117            } else {
118                //閲覧履歴の中で一番古いものを削除して新規追加
119                $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
120                $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
121                $where = "customer_id = ? AND update_date = ? ";
122                $arrval = array($objCustomer->getValue("customer_id"), $old);
123                //削除
124                $objQuery->delete($table, $where, $arrval);
125                //追加
126                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
127            }
128        */
129        }
130
131
132        // 規格選択セレクトボックスの作成
133        $this = $this->lfMakeSelect($this, $tmp_id);
134
135        // 商品IDをFORM内に保持する。
136        $this->tpl_product_id = $tmp_id;
137
138        if (!isset($_['mode'])) $_POST['mode'] = "";
139
140        switch($_POST['mode']) {
141        case 'cart':
142            // 入力値の変換
143            $this->objFormParam->convParam();
144            $this->arrErr = $this->lfCheckError();
145            if(count($this->arrErr) == 0) {
146                $objCartSess = new SC_CartSession();
147                $classcategory_id1 = $_POST['classcategory_id1'];
148                $classcategory_id2 = $_POST['classcategory_id2'];
149
150                // 規格1が設定されていない場合
151                if(!$this->tpl_classcat_find1) {
152                    $classcategory_id1 = '0';
153                }
154
155                // 規格2が設定されていない場合
156                if(!$this->tpl_classcat_find2) {
157                    $classcategory_id2 = '0';
158                }
159
160                $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
161                $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
162                header("Location: " . URL_CART_TOP);
163
164                exit;
165            }
166            break;
167
168        default:
169            break;
170        }
171
172        $objQuery = new SC_Query();
173        // DBから商品情報を取得する。
174        $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id));
175        $this->arrProduct = $arrRet[0];
176
177        // 商品コードの取得
178        $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
179        $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
180        $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
181        $this->arrProductCode = $arrProductCode["product_code"];
182
183        // 購入制限数を取得
184        if($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
185          $this->tpl_sale_limit = SALE_LIMIT_MAX;
186        } else {
187          $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
188        }
189
190        // サブタイトルを取得
191        $arrFirstCat = SC_Utils_Ex::sfGetFirstCat($arrRet[0]['category_id']);
192        $this->tpl_subtitle = $arrFirstCat['name'];
193
194        // DBからのデータを引き継ぐ
195        $this->objUpFile->setDBFileList($this->arrProduct);
196        // ファイル表示用配列を渡す
197        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
198        // 支払方法の取得
199        $this->arrPayment = $this->lfGetPayment();
200        // 入力情報を渡す
201        $this->arrForm = $this->objFormParam->getFormParamList();
202        //レビュー情報の取得
203        $this->arrReview = $this->lfGetReviewData($tmp_id);
204        // トラックバック情報の取得
205
206        // トラックバック機能の稼働状況チェック
207        if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
208            $this->arrTrackbackView = "OFF";
209        } else {
210            $this->arrTrackbackView = "ON";
211            $this->arrTrackback = $this->lfGetTrackbackData($tmp_id);
212        }
213        $this->trackback_url = TRACKBACK_TO_URL . $tmp_id;
214        // タイトルに商品名を入れる
215        $this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
216        //オススメ商品情報表示
217        $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
218        //この商品を買った人はこんな商品も買っています
219        $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
220
221        // 拡大画像のウィンドウサイズをセット
222        $image_path = IMAGE_SAVE_DIR . basename($this->arrFile["main_large_image"]["filepath"]);
223        list($large_width, $large_height) = getimagesize($image_path);
224        $this->tpl_large_width = $large_width + 60;
225        $this->tpl_large_height = $large_height + 80;
226
227        $this->lfConvertParam();
228
229        $objView->assignobj($this);
230        $objView->display(SITE_FRAME);
231    }
232
233    /**
234     * デストラクタ.
235     *
236     * @return void
237     */
238    function destroy() {
239        parent::destroy();
240    }
241
242    /* ファイル情報の初期化 */
243    function lfInitFile() {
244        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg','gif'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
245        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
246        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg'), IMAGE_SIZE, false, LARGE_IMAGE_HEIGHT, LARGE_IMAGE_HEIGHT);
247        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
248            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);
249            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg'), IMAGE_SIZE, false, LARGE_SUBIMAGE_HEIGHT, LARGE_SUBIMAGE_HEIGHT);
250        }
251        $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg'), IMAGE_SIZE, false, NORMAL_IMAGE_HEIGHT, NORMAL_IMAGE_HEIGHT);
252        $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
253    }
254
255    /* 規格選択セレクトボックスの作成 */
256    function lfMakeSelect($this, $product_id) {
257
258        $objDb = new SC_Helper_DB_Ex();
259        $classcat_find1 = false;
260        $classcat_find2 = false;
261        // 在庫ありの商品の有無
262        $stock_find = false;
263
264        // 規格名一覧
265        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
266        // 規格分類名一覧
267        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
268        // 商品規格情報の取得
269        $arrProductsClass = $this->lfGetProductsClass($product_id);
270
271        // 規格1クラス名の取得
272        $this->tpl_class_name1 = isset($arrClassName[$arrProductsClass[0]['class_id1']])
273                                        ? $arrClassName[$arrProductsClass[0]['class_id1']] : "";
274        // 規格2クラス名の取得
275        $this->tpl_class_name2 = isset($arrClassName[$arrProductsClass[0]['class_id2']])
276                                        ? $arrClassName[$arrProductsClass[0]['class_id2']] : "";
277
278        // すべての組み合わせ数
279        $count = count($arrProductsClass);
280
281        $classcat_id1 = "";
282
283        $arrSele = array();
284        $arrList = array();
285
286        $list_id = 0;
287        $arrList[0] = "\tlist0 = new Array('選択してください'";
288        $arrVal[0] = "\tval0 = new Array(''";
289
290        for ($i = 0; $i < $count; $i++) {
291            // 在庫のチェック
292            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
293                continue;
294            }
295
296            $stock_find = true;
297
298            // 規格1のセレクトボックス用
299            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
300                $arrList[$list_id].=");\n";
301                $arrVal[$list_id].=");\n";
302                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
303                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
304                $list_id++;
305            }
306
307            // 規格2のセレクトボックス用
308            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
309
310            // セレクトボックス表示値
311            if (!isset($arrList[$list_id])) $arrList[$list_id] = "";
312            if($arrList[$list_id] == "") {
313                $arrList[$list_id] = "\tlist".$list_id." = new Array('選択してください', '".$arrClassCatName[$classcat_id2]."'";
314            } else {
315                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
316            }
317
318            // セレクトボックスPOST値
319            if (!isset($arrVal[$list_id])) $arrVal[$list_id] = "";
320            if($arrVal[$list_id] == "") {
321                $arrVal[$list_id] = "\tval".$list_id." = new Array('', '".$classcat_id2."'";
322            } else {
323                $arrVal[$list_id].= ", '".$classcat_id2."'";
324            }
325        }
326
327        $arrList[$list_id].=");\n";
328        $arrVal[$list_id].=");\n";
329
330        // 規格1
331        $this->arrClassCat1 = $arrSele;
332
333        $lists = "\tlists = new Array(";
334        $no = 0;
335
336        foreach($arrList as $val) {
337            $this->tpl_javascript.= $val;
338            if ($no != 0) {
339                $lists.= ",list".$no;
340            } else {
341                $lists.= "list".$no;
342            }
343            $no++;
344        }
345        $this->tpl_javascript.=$lists.");\n";
346
347        $vals = "\tvals = new Array(";
348        $no = 0;
349
350        foreach($arrVal as $val) {
351            $this->tpl_javascript.= $val;
352            if ($no != 0) {
353                $vals.= ",val".$no;
354            } else {
355                $vals.= "val".$no;
356            }
357            $no++;
358        }
359        $this->tpl_javascript.=$vals.");\n";
360
361        // 選択されている規格2ID
362        if (!isset($_POST['classcategory_id2'])) $_POST['classcategory_id2'] = "";
363        $this->tpl_onload = "lnSetSelect('form1', 'classcategory_id1', 'classcategory_id2', '" . htmlspecialchars($_POST['classcategory_id2'], ENT_QUOTES) . "');";
364
365        // 規格1が設定されている
366        if($arrProductsClass[0]['classcategory_id1'] != '0') {
367            $classcat_find1 = true;
368        }
369
370        // 規格2が設定されている
371        if($arrProductsClass[0]['classcategory_id2'] != '0') {
372            $classcat_find2 = true;
373        }
374
375        $this->tpl_classcat_find1 = $classcat_find1;
376        $this->tpl_classcat_find2 = $classcat_find2;
377        $this->tpl_stock_find = $stock_find;
378
379        return $this;
380    }
381
382    /* パラメータ情報の初期化 */
383    function lfInitParam() {
384        $this->objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
385        $this->objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
386        $this->objFormParam->addParam("個数", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
387    }
388
389    /* 商品規格情報の取得 */
390    function lfGetProductsClass($product_id) {
391        $arrRet = array();
392        if(SC_Utils_Ex::sfIsInt($product_id)) {
393            // 商品規格取得
394            $objQuery = new SC_Query();
395            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
396            $table = "vw_product_class AS prdcls";
397            $where = "product_id = ?";
398            $objQuery->setorder("rank1 DESC, rank2 DESC");
399            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
400        }
401        return $arrRet;
402    }
403
404    /* 登録済みオススメ商品の読み込み */
405    function lfPreGetRecommendProducts($product_id) {
406        $arrRecommend = array();
407        $objQuery = new SC_Query();
408        $objQuery->setorder("rank DESC");
409        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
410        $max = count($arrRet);
411        $no = 0;
412        for($i = 0; $i < $max; $i++) {
413            $where = "del_flg = 0 AND product_id = ? AND status = 1";
414            $arrProductInfo = $objQuery->select("main_list_image, price02_min, price02_max, price01_min, price01_max, name, point_rate", "vw_products_allclass  AS allcls", $where, array($arrRet[$i]['recommend_product_id']));
415
416            if(count($arrProductInfo) > 0) {
417                $arrRecommend[$no] = $arrProductInfo[0];
418                $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
419                $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
420                $no++;
421            }
422        }
423        return $arrRecommend;
424    }
425
426    /* 入力内容のチェック */
427    function lfCheckError() {
428        // 入力データを渡す。
429        $arrRet =  $this->objFormParam->getHashArray();
430        $objErr = new SC_CheckError($arrRet);
431        $objErr->arrErr = $this->objFormParam->checkError();
432
433        // 複数項目チェック
434        if ($this->tpl_classcat_find1) {
435            $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
436        }
437        if ($this->tpl_classcat_find2) {
438            $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
439        }
440
441        return $objErr->arrErr;
442    }
443
444    //閲覧履歴新規登録
445    function lfRegistReadingData($tmp_id, $customer_id){
446        $objQuery = new SC_Query;
447        $sqlval['customer_id'] = $customer_id;
448        $sqlval['reading_product_id'] = $tmp_id;
449        $sqlval['create_date'] = 'NOW()';
450        $sqlval['update_date'] = 'NOW()';
451        $objQuery->insert("dtb_customer_reading", $sqlval);
452    }
453
454    //この商品を買った人はこんな商品も買っています
455    function lfGetRelateProducts($tmp_id) {
456        $objQuery = new SC_Query;
457        //自動抽出
458        $objQuery->setorder("random()");
459        //表示件数の制限
460        $objQuery->setlimit(RELATED_PRODUCTS_MAX);
461        //検索条件
462        $col = "name, main_list_image, price01_min, price02_min, price01_max, price02_max, point_rate";
463        $from = "vw_products_allclass AS allcls ";
464        $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? ";
465        $arrval[] = $tmp_id;
466        //結果の取得
467        $arrProducts = $objQuery->select($col, $from, $where, $arrval);
468
469        return $arrProducts;
470    }
471
472    //商品ごとのレビュー情報を取得する
473    function lfGetReviewData($id) {
474        $objQuery = new SC_Query;
475        //商品ごとのレビュー情報を取得する
476        $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
477        $from = "dtb_review";
478        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
479        $arrval[] = $id;
480        $arrReview = $objQuery->select($col, $from, $where, $arrval);
481        return $arrReview;
482    }
483
484    /*
485     * 商品ごとのトラックバック情報を取得する
486     *
487     * @param $product_id
488     * @return $arrTrackback
489     */
490    function lfGetTrackbackData($product_id) {
491
492        $arrTrackback = array();
493
494        $objQuery = new SC_Query;
495        //商品ごとのトラックバック情報を取得する
496        $col = "blog_name, url, title, excerpt, title, create_date";
497        $from = "dtb_trackback";
498        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
499        $arrval[] = $product_id;
500        $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
501        return $arrTrackback;
502    }
503
504    //支払方法の取得
505    //payment_id    1:クレジット 2:ショッピングローン
506    function lfGetPayment() {
507        $objQuery = new SC_Query;
508        $col = "payment_id, rule, payment_method";
509        $from = "dtb_payment";
510        $where = "del_flg = 0";
511        $order = "payment_id";
512        $objQuery->setorder($order);
513        $arrRet = $objQuery->select($col, $from, $where);
514        return $arrRet;
515    }
516
517    function lfConvertParam() {
518        if (!isset($this->arrForm['quantity']['value'])) $this->arrForm['quantity']['value'] = "";
519        $value = $this->arrForm['quantity']['value'];
520        $this->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
521    }
522}
523?>
Note: See TracBrowser for help on using the repository browser.