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

Revision 18407, 34.6 KB checked in by kajiwara, 14 years ago (diff)

#524 商品一覧で、複数のカテゴリに割り当てたれた商品の並び順が不正となる 不具合を修正(オススメ商品表示にて不具合が出ていたので修正)

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