source: branches/version-2/data/class/pages/products/LC_Page_Products_Detail.php @ 18176

Revision 18176, 34.8 KB checked in by kajiwara, 15 years ago (diff)

r18028 にリビジョン戻し

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