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

Revision 18069, 34.4 KB checked in by Seasoft, 15 years ago (diff)

merge r17931, r17932, r17933
・取得元: version-2_4
【取得元のログメッセージ】

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