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

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