source: trunk/data/class/pages/products/LC_Page_Products_Detail.php @ 18758

Revision 18758, 34.1 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.4 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=223

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