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

Revision 18142, 34.7 KB checked in by ramrun, 15 years ago (diff)

商品一覧ページでcategory_id、商品詳細ページでproduct_idの正当性をチェック

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