source: branches/comu-ver2/data/class/pages/products/LC_Page_Products_Detail.php @ 17579

Revision 17579, 34.1 KB checked in by Seasoft, 16 years ago (diff)

merge r17463,r17464,r17465,r17468,r17472,r17473,r17493,r17497,r17500,r17501,r17504

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2007 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_PATH . "pages/LC_Page.php");
26
27/**
28 * 商品詳細 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Products_Detail extends LC_Page {
35
36    /** ステータス */
37    var $arrSTATUS;
38
39    /** ステータス画像 */
40    var $arrSTATUS_IMAGE;
41
42    /** 発送予定日 */
43    var $arrDELIVERYDATE;
44
45    /** おすすめレベル */
46    var $arrRECOMMEND;
47
48    /** フォームパラメータ */
49    var $objFormParam;
50
51    /** アップロードファイル */
52    var $objUpFile;
53
54    // }}}
55    // {{{ functions
56
57    /**
58     * Page を初期化する.
59     *
60     * @return void
61     */
62    function init() {
63        parent::init();
64        $masterData = new SC_DB_MasterData_Ex();
65        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
66        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
67        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
68        $this->arrRECOMMEND = $masterData->getMasterData("mtb_recommend");
69    }
70
71    /**
72     * Page のプロセス.
73     *
74     * @return void
75     */
76    function process() {
77        $objView = new SC_SiteView();
78        $objCustomer = new SC_Customer();
79        $objQuery = new SC_Query();
80        $objDb = new SC_Helper_DB_Ex();
81
82        // レイアウトデザインを取得
83        $helper = new SC_Helper_PageLayout_Ex();
84        $helper->sfGetPageLayout($this, false, "products/detail.php");
85
86        if(isset($_POST['mode']) && $_POST['favorite_product_id'] != "" && $_POST['mode'] == "add_favorite") {
87            // 値の正当性チェック
88            if(!SC_Utils_Ex::sfIsInt($_POST['favorite_product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $_POST['favorite_product_id'], "del_flg = 0 AND status = 1")) {
89                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
90                exit;
91            } else {
92                $this->arrErr = $this->lfCheckError();
93                if(count($this->arrErr) == 0) {
94                    $customer_id = $objCustomer->getValue('customer_id');
95                    $this->lfRegistFavoriteProduct($customer_id, $_POST['favorite_product_id']);
96                }
97            }
98        }
99
100        // パラメータ管理クラス
101        $this->objFormParam = new SC_FormParam();
102        // パラメータ情報の初期化
103        $this->lfInitParam();
104        // POST値の取得
105        $this->objFormParam->setParam($_POST);
106
107        // ファイル管理クラス
108        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
109        // ファイル情報の初期化
110        $this->lfInitFile();
111
112        // 管理機能からの確認の場合は、非公開の商品も表示する。
113        // XXX 若干脆弱な気がする。ログイン状態か確認するのが望ましいかと。
114        if(isset($_GET['admin']) && $_GET['admin'] == 'on') {
115            SC_Utils_Ex::sfIsSuccess(new SC_Session());
116            $status = true;
117            $where = "del_flg = 0";
118        } else {
119            $status = false;
120            $where = "del_flg = 0 AND status = 1";
121        }
122
123        if(isset($_POST['mode']) && $_POST['mode'] != "") {
124            $tmp_id = $_POST['product_id'];
125        } else {
126            $tmp_id = $_GET['product_id'];
127        }
128
129        // 値の正当性チェック
130        if(!SC_Utils_Ex::sfIsInt($_GET['product_id'])
131                || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, $where)) {
132            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
133        }
134        // ログイン判定
135        if($objCustomer->isLoginSuccess()) {
136            //お気に入りボタン表示
137            $this->tpl_login = true;
138
139        /* 閲覧ログ機能は現在未使用
140
141            $table = "dtb_customer_reading";
142            $where = "customer_id = ? ";
143            $arrval[] = $objCustomer->getValue('customer_id');
144            //顧客の閲覧商品数
145            $rpcnt = $objQuery->count($table, $where, $arrval);
146
147            //閲覧数が設定数以下
148            if ($rpcnt < CUSTOMER_READING_MAX){
149                //閲覧履歴に新規追加
150                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
151            } else {
152                //閲覧履歴の中で一番古いものを削除して新規追加
153                $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
154                $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
155                $where = "customer_id = ? AND update_date = ? ";
156                $arrval = array($objCustomer->getValue("customer_id"), $old);
157                //削除
158                $objQuery->delete($table, $where, $arrval);
159                //追加
160                lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
161            }
162        */
163        }
164
165
166        // 規格選択セレクトボックスの作成
167        $this->lfMakeSelect($tmp_id);
168
169        // 商品IDをFORM内に保持する。
170        $this->tpl_product_id = $tmp_id;
171
172        if (!isset($_POST['mode'])) $_POST['mode'] = "";
173
174        switch($_POST['mode']) {
175        case 'cart':
176            // 入力値の変換
177            $this->objFormParam->convParam();
178            $this->arrErr = $this->lfCheckError();
179            if(count($this->arrErr) == 0) {
180                $objCartSess = new SC_CartSession();
181                $classcategory_id1 = $_POST['classcategory_id1'];
182                $classcategory_id2 = $_POST['classcategory_id2'];
183
184                // 規格1が設定されていない場合
185                if(!$this->tpl_classcat_find1) {
186                    $classcategory_id1 = '0';
187                }
188
189                // 規格2が設定されていない場合
190                if(!$this->tpl_classcat_find2) {
191                    $classcategory_id2 = '0';
192                }
193
194                $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
195                $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
196                $this->sendRedirect($this->getLocation(URL_CART_TOP));
197                exit;
198            }
199            break;
200
201        default:
202            break;
203        }
204
205        $objQuery = new SC_Query();
206        // DBから商品情報を取得する。
207        $arrRet = $objQuery->select("*, (SELECT count(*) FROM dtb_customer_favorite_products WHERE product_id = alldtl.product_id AND customer_id = ?) AS favorite_count", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($objCustomer->getValue('customer_id'), $tmp_id));
208        $this->arrProduct = $arrRet[0];
209
210        // 商品コードの取得
211        $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
212        $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
213        $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
214        $this->arrProductCode = $arrProductCode["product_code"];
215
216        // 購入制限数を取得
217        if($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
218          $this->tpl_sale_limit = SALE_LIMIT_MAX;
219        } else {
220          $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
221        }
222       
223        // サブタイトルを取得
224        $this->tpl_subtitle = $this->arrProduct['name'];
225       
226        // 大カテゴリーを取得
227        $arrCategory_id = $objDb->sfGetCategoryId($arrRet[0]['product_id'], $status);
228        $arrFirstCat = $objDb->sfGetFirstCat($arrCategory_id[0]);
229        $this->tpl_FirstCatName = $arrFirstCat['name'];
230       
231        // 関連カテゴリを取得
232        $this->arrRelativeCat = $objDb->sfGetMultiCatTree($tmp_id);
233
234        $this->lfSetFile();
235        // 支払方法の取得
236        $this->arrPayment = $this->lfGetPayment();
237        // 入力情報を渡す
238        $this->arrForm = $this->objFormParam->getFormParamList();
239        //レビュー情報の取得
240        $this->arrReview = $this->lfGetReviewData($tmp_id);
241        // トラックバック情報の取得
242
243        // トラックバック機能の稼働状況チェック
244        if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
245            $this->arrTrackbackView = "OFF";
246        } else {
247            $this->arrTrackbackView = "ON";
248            $this->arrTrackback = $this->lfGetTrackbackData($tmp_id);
249        }
250        $this->trackback_url = TRACKBACK_TO_URL . $tmp_id;
251        //関連商品情報表示
252        $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
253        //この商品を買った人はこんな商品も買っています
254        $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
255
256        // 拡大画像のウィンドウサイズをセット
257        if (isset($this->arrFile["main_large_image"])) {
258            $image_path = IMAGE_SAVE_DIR . basename($this->arrFile["main_large_image"]["filepath"]);
259        } else {
260            $image_path = "";
261        }
262
263        list($large_width, $large_height) = getimagesize($image_path);
264        $this->tpl_large_width = $large_width + 60;
265        $this->tpl_large_height = $large_height + 80;
266
267        $this->lfConvertParam();
268
269        $objView->assignobj($this);
270        $objView->display(SITE_FRAME);
271    }
272
273    /**
274     * デストラクタ.
275     *
276     * @return void
277     */
278    function destroy() {
279        parent::destroy();
280    }
281
282    /**
283     * モバイルページを初期化する.
284     *
285     * @return void
286     */
287    function mobileInit() {
288        $this->init();
289        $this->tpl_mainpage = "products/detail.tpl";
290    }
291
292    /**
293     * Page のプロセス(モバイル).
294     *
295     * FIXME 要リファクタリング
296     *
297     * @return void
298     */
299    function mobileProcess() {
300        $objView = new SC_MobileView();
301        $objCustomer = new SC_Customer();
302        $objQuery = new SC_Query();
303        $objDb = new SC_Helper_DB_Ex();
304
305        // パラメータ管理クラス
306        $this->objFormParam = new SC_FormParam();
307        // パラメータ情報の初期化
308        $this->lfInitParam();
309        // POST値の取得
310        $this->objFormParam->setParam($_POST);
311
312        // ファイル管理クラス
313        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
314        // ファイル情報の初期化
315        $this->lfInitFile();
316
317        if (!isset($_POST['mode'])) $_POST['mode'] = "";
318
319        if(!empty($_POST['mode'])) {
320            $tmp_id = $_POST['product_id'];
321        } else {
322            $tmp_id = $_GET['product_id'];
323        }
324
325        // 値の正当性チェック
326        if(!SC_Utils_Ex::sfIsInt($tmp_id)
327                || !$objDb->sfIsRecord("dtb_products", "product_id", $tmp_id, 'del_flg = 0 AND status = 1')) {
328            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
329        }
330
331        // ログイン判定
332        if($objCustomer->isLoginSuccess(true)) {
333            //お気に入りボタン表示
334            $this->tpl_login = true;
335
336            /* 閲覧ログ機能は現在未使用
337
338               $table = "dtb_customer_reading";
339               $where = "customer_id = ? ";
340               $arrval[] = $objCustomer->getValue('customer_id');
341               //顧客の閲覧商品数
342               $rpcnt = $objQuery->count($table, $where, $arrval);
343
344               //閲覧数が設定数以下
345               if ($rpcnt < CUSTOMER_READING_MAX){
346               //閲覧履歴に新規追加
347               lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
348               } else {
349               //閲覧履歴の中で一番古いものを削除して新規追加
350               $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
351               $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
352               $where = "customer_id = ? AND update_date = ? ";
353               $arrval = array($objCustomer->getValue("customer_id"), $old);
354               //削除
355               $objQuery->delete($table, $where, $arrval);
356               //追加
357               lfRegistReadingData($tmp_id, $objCustomer->getValue('customer_id'));
358               }
359            */
360        }
361
362
363        // 規格選択セレクトボックスの作成
364        $this->lfMakeSelectMobile($this, $tmp_id);
365
366        // 商品IDをFORM内に保持する。
367        $this->tpl_product_id = $tmp_id;
368
369        switch($_POST['mode']) {
370        case 'select':
371            // 規格1が設定されている場合
372            if($this->tpl_classcat_find1) {
373                // templateの変更
374                $this->tpl_mainpage = "products/select_find1.tpl";
375                break;
376            }
377
378        case 'select2':
379            $this->arrErr = $this->lfCheckError();
380
381            // 規格1が設定されている場合
382            if($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
383                // templateの変更
384                $this->tpl_mainpage = "products/select_find1.tpl";
385                break;
386            }
387
388            // 規格2が設定されている場合
389            if($this->tpl_classcat_find2) {
390                $this->arrErr = array();
391
392                $this->tpl_mainpage = "products/select_find2.tpl";
393                break;
394            }
395
396        case 'selectItem':
397            $this->arrErr = $this->lfCheckError();
398
399            // 規格1が設定されている場合
400            if($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
401                // templateの変更
402                $this->tpl_mainpage = "products/select_find2.tpl";
403                break;
404            }
405            // 商品数の選択を行う
406            $this->tpl_mainpage = "products/select_item.tpl";
407            break;
408
409        case 'cart':
410            // 入力値の変換
411            $this->objFormParam->convParam();
412            $this->arrErr = $this->lfCheckError();
413            if(count($this->arrErr) == 0) {
414                $objCartSess = new SC_CartSession();
415                $classcategory_id1 = $_POST['classcategory_id1'];
416                $classcategory_id2 = $_POST['classcategory_id2'];
417
418                // 規格1が設定されていない場合
419                if(!$this->tpl_classcat_find1) {
420                    $classcategory_id1 = '0';
421                }
422
423                // 規格2が設定されていない場合
424                if(!$this->tpl_classcat_find2) {
425                    $classcategory_id2 = '0';
426                }
427
428                $objCartSess->setPrevURL($_SERVER['REQUEST_URI']);
429                $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
430                $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true);
431                exit;
432            }
433            break;
434
435        default:
436            break;
437        }
438
439        $objQuery = new SC_Query();
440        // DBから商品情報を取得する。
441        $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($tmp_id));
442        $this->arrProduct = $arrRet[0];
443
444        // 商品コードの取得
445        $code_sql = "SELECT product_code FROM dtb_products_class AS prdcls WHERE prdcls.product_id = ? GROUP BY product_code ORDER BY product_code";
446        $arrProductCode = $objQuery->getall($code_sql, array($tmp_id));
447        $arrProductCode = SC_Utils_Ex::sfswaparray($arrProductCode);
448        $this->arrProductCode = $arrProductCode["product_code"];
449
450        // 購入制限数を取得
451        if($this->arrProduct['sale_unlimited'] == 1 || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
452            $this->tpl_sale_limit = SALE_LIMIT_MAX;
453        } else {
454            $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
455        }
456
457        // サブタイトルを取得
458        $arrFirstCat = $objDb->sfGetFirstCat($arrRet[0]['category_id']);
459        $tpl_subtitle = $arrFirstCat['name'];
460        $this->tpl_subtitle = $tpl_subtitle;
461
462        // ファイル情報のセット
463        $this->lfSetFile();
464        // 支払方法の取得
465        $this->arrPayment = $this->lfGetPayment();
466        // 入力情報を渡す
467        $this->arrForm = $this->objFormParam->getFormParamList();
468        //レビュー情報の取得
469        $this->arrReview = $this->lfGetReviewData($tmp_id);
470        // タイトルに商品名を入れる
471        $this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
472        //関連商品情報表示
473        $this->arrRecommend = $this->lfPreGetRecommendProducts($tmp_id);
474        //この商品を買った人はこんな商品も買っています
475        $this->arrRelateProducts = $this->lfGetRelateProducts($tmp_id);
476
477        // 拡大画像のウィンドウサイズをセット
478        if (!empty($this->arrFile["main_large_image"])) {
479            list($large_width, $large_height) = getimagesize(IMAGE_SAVE_DIR . basename($this->arrFile["main_large_image"]["filepath"]));
480        }
481        $this->tpl_large_width = isset($large_width) ? $large_width + 60 : 0;
482        $this->tpl_large_height = isset($large_height) ? $large_height + 80 : 0;
483
484        $objView->assignobj($this);
485        $objView->display(SITE_FRAME);
486    }
487
488    /* ファイル情報の初期化 */
489    function lfInitFile() {
490        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg','gif'),IMAGE_SIZE, true, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
491        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
492        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg'), IMAGE_SIZE, false, LARGE_IMAGE_HEIGHT, LARGE_IMAGE_HEIGHT);
493        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
494            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);
495            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg'), IMAGE_SIZE, false, LARGE_SUBIMAGE_HEIGHT, LARGE_SUBIMAGE_HEIGHT);
496        }
497        $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg'), IMAGE_SIZE, false, NORMAL_IMAGE_HEIGHT, NORMAL_IMAGE_HEIGHT);
498        $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
499    }
500
501    /* 規格選択セレクトボックスの作成 */
502    function lfMakeSelect($product_id) {
503
504        $objDb = new SC_Helper_DB_Ex();
505        $classcat_find1 = false;
506        $classcat_find2 = false;
507        // 在庫ありの商品の有無
508        $stock_find = false;
509
510        // 規格名一覧
511        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
512        // 規格分類名一覧
513        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
514        // 商品規格情報の取得
515        $arrProductsClass = $this->lfGetProductsClass($product_id);
516
517        // 規格1クラス名の取得
518        $this->tpl_class_name1 = isset($arrClassName[$arrProductsClass[0]['class_id1']])
519                                        ? $arrClassName[$arrProductsClass[0]['class_id1']] : "";
520        // 規格2クラス名の取得
521        $this->tpl_class_name2 = isset($arrClassName[$arrProductsClass[0]['class_id2']])
522                                        ? $arrClassName[$arrProductsClass[0]['class_id2']] : "";
523
524        // すべての組み合わせ数
525        $count = count($arrProductsClass);
526
527        $classcat_id1 = "";
528
529        $arrSele = array();
530        $arrList = array();
531
532        $list_id = 0;
533        $arrList[0] = "\tlist0 = new Array('選択してください'";
534        $arrVal[0] = "\tval0 = new Array(''";
535
536        for ($i = 0; $i < $count; $i++) {
537            // 在庫のチェック
538            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
539                continue;
540            }
541
542            $stock_find = true;
543
544            // 規格1のセレクトボックス用
545            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
546                $arrList[$list_id].=");\n";
547                $arrVal[$list_id].=");\n";
548                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
549                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
550                $list_id++;
551            }
552
553            // 規格2のセレクトボックス用
554            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
555
556            // セレクトボックス表示値
557            if (!isset($arrList[$list_id])) $arrList[$list_id] = "";
558            if($arrList[$list_id] == "") {
559                $arrList[$list_id] = "\tlist".$list_id." = new Array('選択してください', '".$arrClassCatName[$classcat_id2]."'";
560            } else {
561                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
562            }
563
564            // セレクトボックスPOST値
565            if (!isset($arrVal[$list_id])) $arrVal[$list_id] = "";
566            if($arrVal[$list_id] == "") {
567                $arrVal[$list_id] = "\tval".$list_id." = new Array('', '".$classcat_id2."'";
568            } else {
569                $arrVal[$list_id].= ", '".$classcat_id2."'";
570            }
571        }
572
573        $arrList[$list_id].=");\n";
574        $arrVal[$list_id].=");\n";
575
576        // 規格1
577        $this->arrClassCat1 = $arrSele;
578
579        $lists = "\tlists = new Array(";
580        $no = 0;
581
582        foreach($arrList as $val) {
583            $this->tpl_javascript.= $val;
584            if ($no != 0) {
585                $lists.= ",list".$no;
586            } else {
587                $lists.= "list".$no;
588            }
589            $no++;
590        }
591        $this->tpl_javascript.=$lists.");\n";
592
593        $vals = "\tvals = new Array(";
594        $no = 0;
595
596        foreach($arrVal as $val) {
597            $this->tpl_javascript.= $val;
598            if ($no != 0) {
599                $vals.= ",val".$no;
600            } else {
601                $vals.= "val".$no;
602            }
603            $no++;
604        }
605        $this->tpl_javascript.=$vals.");\n";
606
607        // 選択されている規格2ID
608        if (!isset($_POST['classcategory_id2'])) $_POST['classcategory_id2'] = "";
609        $this->tpl_onload = "lnSetSelect('form1', 'classcategory_id1', 'classcategory_id2', '" . htmlspecialchars($_POST['classcategory_id2'], ENT_QUOTES) . "');";
610
611        // 規格1が設定されている
612        if($arrProductsClass[0]['classcategory_id1'] != '0') {
613            $classcat_find1 = true;
614        }
615
616        // 規格2が設定されている
617        if($arrProductsClass[0]['classcategory_id2'] != '0') {
618            $classcat_find2 = true;
619        }
620
621        $this->tpl_classcat_find1 = $classcat_find1;
622        $this->tpl_classcat_find2 = $classcat_find2;
623        $this->tpl_stock_find = $stock_find;
624    }
625
626    /* 規格選択セレクトボックスの作成
627     * FIXME 要リファクタリング
628     */
629    function lfMakeSelectMobile(&$objPage, $product_id) {
630
631        $objDb = new SC_Helper_DB_Ex();
632        $classcat_find1 = false;
633        $classcat_find2 = false;
634        // 在庫ありの商品の有無
635        $stock_find = false;
636
637        // 規格名一覧
638        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
639        // 規格分類名一覧
640        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
641        // 商品規格情報の取得
642        $arrProductsClass = $this->lfGetProductsClass($product_id);
643
644        // 規格1クラス名の取得
645        $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
646        // 規格2クラス名の取得
647        $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
648
649        // すべての組み合わせ数
650        $count = count($arrProductsClass);
651
652        $classcat_id1 = "";
653
654        $arrSele1 = array();
655        $arrSele2 = array();
656
657        for ($i = 0; $i < $count; $i++) {
658            // 在庫のチェック
659            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
660                continue;
661            }
662
663            $stock_find = true;
664
665            // 規格1のセレクトボックス用
666            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
667                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
668                $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
669            }
670
671            // 規格2のセレクトボックス用
672            if($arrProductsClass[$i]['classcategory_id1'] == $_POST['classcategory_id1'] and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
673                $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
674                $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
675            }
676        }
677
678        // 規格1
679        $objPage->arrClassCat1 = $arrSele1;
680        $objPage->arrClassCat2 = $arrSele2;
681
682        // 規格1が設定されている
683        if($arrProductsClass[0]['classcategory_id1'] != '0') {
684            $classcat_find1 = true;
685        }
686
687        // 規格2が設定されている
688        if($arrProductsClass[0]['classcategory_id2'] != '0') {
689            $classcat_find2 = true;
690        }
691
692        $objPage->tpl_classcat_find1 = $classcat_find1;
693        $objPage->tpl_classcat_find2 = $classcat_find2;
694        $objPage->tpl_stock_find = $stock_find;
695    }
696
697    /* パラメータ情報の初期化 */
698    function lfInitParam() {
699        $this->objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
700        $this->objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
701        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
702    }
703
704    /* 商品規格情報の取得 */
705    function lfGetProductsClass($product_id) {
706        $arrRet = array();
707        if(SC_Utils_Ex::sfIsInt($product_id)) {
708            // 商品規格取得
709            $objQuery = new SC_Query();
710            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
711            $table = "vw_product_class AS prdcls";
712            $where = "product_id = ?";
713            $objQuery->setorder("rank1 DESC, rank2 DESC");
714            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
715        }
716        return $arrRet;
717    }
718
719    /* 登録済み関連商品の読み込み */
720    function lfPreGetRecommendProducts($product_id) {
721        $arrRecommend = array();
722        $objQuery = new SC_Query();
723        $objQuery->setorder("rank DESC");
724        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
725        $max = count($arrRet);
726        $no = 0;
727        $from = "vw_products_allclass AS T1 "
728                . " JOIN ("
729                . " SELECT max(T2.rank) AS product_rank, "
730                . "        T2.product_id"
731                . "   FROM dtb_product_categories T2  "
732                . " GROUP BY product_id) AS T3 USING (product_id)";
733        $objQuery->setorder("product_rank DESC");
734        for($i = 0; $i < $max; $i++) {
735            $where = "del_flg = 0 AND T3.product_id = ? AND status = 1";
736            $arrProductInfo = $objQuery->select("DISTINCT main_list_image, price02_min, price02_max, price01_min, price01_max, name, point_rate, product_rank", $from, $where, array($arrRet[$i]['recommend_product_id']));
737
738            if(count($arrProductInfo) > 0) {
739                $arrRecommend[$no] = $arrProductInfo[0];
740                $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
741                $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
742                $no++;
743            }
744        }
745        return $arrRecommend;
746    }
747
748    /* 入力内容のチェック */
749    function lfCheckError() {
750        if ($_POST['mode'] == "add_favorite") {
751            $objCustomer = new SC_Customer();
752            $objErr = new SC_CheckError();
753            $customer_id = $objCustomer->getValue('customer_id');
754            if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
755                $objErr->arrErr['add_favorite'.$favorite_product_id] = "※ この商品は既にお気に入りに追加されています。<br />";
756            }
757        } else {
758            // 入力データを渡す。
759            $arrRet =  $this->objFormParam->getHashArray();
760            $objErr = new SC_CheckError($arrRet);
761            $objErr->arrErr = $this->objFormParam->checkError();
762
763            // 複数項目チェック
764            if ($this->tpl_classcat_find1) {
765                $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
766            }
767            if ($this->tpl_classcat_find2) {
768                $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
769            }
770        }
771
772        return $objErr->arrErr;
773    }
774
775    //閲覧履歴新規登録
776    function lfRegistReadingData($tmp_id, $customer_id){
777        $objQuery = new SC_Query;
778        $sqlval['customer_id'] = $customer_id;
779        $sqlval['reading_product_id'] = $tmp_id;
780        $sqlval['create_date'] = 'NOW()';
781        $sqlval['update_date'] = 'NOW()';
782        $objQuery->insert("dtb_customer_reading", $sqlval);
783    }
784
785    //この商品を買った人はこんな商品も買っています FIXME
786    function lfGetRelateProducts($tmp_id) {
787        $objQuery = new SC_Query;
788        //自動抽出
789        $objQuery->setorder("random()");
790        //表示件数の制限
791        $objQuery->setlimit(RELATED_PRODUCTS_MAX);
792        //検索条件
793        $col = "name, main_list_image, price01_min, price02_min, price01_max, price02_max, point_rate";
794        $from = "vw_products_allclass AS allcls ";
795        $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? ";
796        $arrval[] = $tmp_id;
797        //結果の取得
798        $arrProducts = $objQuery->select($col, $from, $where, $arrval);
799
800        return $arrProducts;
801    }
802
803    //商品ごとのレビュー情報を取得する
804    function lfGetReviewData($id) {
805        $objQuery = new SC_Query;
806        //商品ごとのレビュー情報を取得する
807        $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
808        $from = "dtb_review";
809        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
810        $arrval[] = $id;
811        $arrReview = $objQuery->select($col, $from, $where, $arrval);
812        return $arrReview;
813    }
814
815    /*
816     * 商品ごとのトラックバック情報を取得する
817     *
818     * @param $product_id
819     * @return $arrTrackback
820     */
821    function lfGetTrackbackData($product_id) {
822
823        $arrTrackback = array();
824
825        $objQuery = new SC_Query;
826        //商品ごとのトラックバック情報を取得する
827        $col = "blog_name, url, title, excerpt, title, create_date";
828        $from = "dtb_trackback";
829        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
830        $arrval[] = $product_id;
831        $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
832        return $arrTrackback;
833    }
834
835    //支払方法の取得
836    //payment_id    1:クレジット 2:ショッピングローン
837    function lfGetPayment() {
838        $objQuery = new SC_Query;
839        $col = "payment_id, rule, payment_method";
840        $from = "dtb_payment";
841        $where = "del_flg = 0";
842        $order = "payment_id";
843        $objQuery->setorder($order);
844        $arrRet = $objQuery->select($col, $from, $where);
845        return $arrRet;
846    }
847
848    function lfConvertParam() {
849        if (!isset($this->arrForm['quantity']['value'])) $this->arrForm['quantity']['value'] = "";
850        $value = $this->arrForm['quantity']['value'];
851        $this->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
852    }
853
854    /*
855     * ファイルの情報をセットする
856     *
857     */
858    function lfSetFile() {
859        // DBからのデータを引き継ぐ
860        $this->objUpFile->setDBFileList($this->arrProduct);
861        // ファイル表示用配列を渡す
862        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
863
864        // サブ画像の有無を判定
865        $this->subImageFlag = false;
866        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
867            if ($this->arrFile["sub_image" . $i]["filepath"] != "") {
868                $this->subImageFlag = true;
869            }
870        }
871    }
872
873    /*
874     * お気に入り商品登録
875     */
876    function lfRegistFavoriteProduct($customer_id, $product_id) {
877        $objQuery = new SC_Query();
878        $objConn = new SC_DbConn();
879        $count = $objConn->getOne("SELECT COUNT(*) FROM dtb_customer_favorite_products WHERE customer_id = ? AND product_id = ?", array($customer_id, $product_id));
880
881        if ($count == 0) {
882            $sqlval['customer_id'] = $customer_id;
883            $sqlval['product_id'] = $product_id;
884
885            $objQuery->begin();
886            $objQuery->insert('dtb_customer_favorite_products', $sqlval);
887            $objQuery->commit();
888        }
889    }
890
891}
892?>
Note: See TracBrowser for help on using the repository browser.