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

Revision 18325, 30.6 KB checked in by Seasoft, 15 years ago (diff)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27if (file_exists(MODULE_PATH . "mdl_gmopg/inc/function.php")) {
28    require_once(MODULE_PATH . "mdl_gmopg/inc/function.php");
29}
30/**
31 * 商品詳細 のページクラス.
32 *
33 * @package Page
34 * @author LOCKON CO.,LTD.
35 * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $
36 */
37class LC_Page_Products_Detail extends LC_Page {
38
39    /** ステータス */
40    var $arrSTATUS;
41
42    /** ステータス画像 */
43    var $arrSTATUS_IMAGE;
44
45    /** 発送予定日 */
46    var $arrDELIVERYDATE;
47
48    /** おすすめレベル */
49    var $arrRECOMMEND;
50
51    /** フォームパラメータ */
52    var $objFormParam;
53
54    /** アップロードファイル */
55    var $objUpFile;
56
57    // }}}
58    // {{{ functions
59
60    /**
61     * Page を初期化する.
62     *
63     * @return void
64     */
65    function init() {
66        parent::init();
67        $masterData = new SC_DB_MasterData_Ex();
68        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
69        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
70        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
71        $this->arrRECOMMEND = $masterData->getMasterData("mtb_recommend");
72    }
73
74    /**
75     * Page のプロセス.
76     *
77     * @return void
78     */
79    function process() {
80        // プロダクトIDの正当性チェック
81        $product_id = $this->lfCheckProductId();
82
83        $objView = new SC_SiteView(strlen($_POST['mode']) == 0);
84        $objCustomer = new SC_Customer();
85        $objQuery = new SC_Query();
86        $objDb = new SC_Helper_DB_Ex();
87
88        // レイアウトデザインを取得
89        $helper = new SC_Helper_PageLayout_Ex();
90        $helper->sfGetPageLayout($this, false, "products/detail.php");
91
92        // ログイン中のユーザが商品をお気に入りにいれる処理
93        if ($objCustomer->isLoginSuccess() === true && strlen($_POST['mode']) > 0 && $_POST['mode'] == "add_favorite" && strlen($_POST['favorite_product_id']) > 0 ) {
94            // 値の正当性チェック
95            if(!SC_Utils_Ex::sfIsInt($_POST['favorite_product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $_POST['favorite_product_id'], "del_flg = 0 AND status = 1")) {
96                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
97                exit;
98            } else {
99                $this->arrErr = $this->lfCheckError();
100                if(count($this->arrErr) == 0) {
101                    $customer_id = $objCustomer->getValue('customer_id');
102                    $this->lfRegistFavoriteProduct($customer_id, $_POST['favorite_product_id']);
103                }
104            }
105        }
106
107        // パラメータ管理クラス
108        $this->objFormParam = new SC_FormParam();
109        // パラメータ情報の初期化
110        $this->lfInitParam();
111        // POST値の取得
112        $this->objFormParam->setParam($_POST);
113
114        // ファイル管理クラス
115        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
116        // ファイル情報の初期化
117        $this->lfInitFile();
118
119        // ログイン判定
120        if ($objCustomer->isLoginSuccess() === true) {
121            //お気に入りボタン表示
122            $this->tpl_login = true;
123
124        /* 閲覧ログ機能は現在未使用
125
126            $table = "dtb_customer_reading";
127            $where = "customer_id = ? ";
128            $arrval[] = $objCustomer->getValue('customer_id');
129            //顧客の閲覧商品数
130            $rpcnt = $objQuery->count($table, $where, $arrval);
131
132            //閲覧数が設定数以下
133            if ($rpcnt < CUSTOMER_READING_MAX){
134                //閲覧履歴に新規追加
135                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
136            } else {
137                //閲覧履歴の中で一番古いものを削除して新規追加
138                $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
139                $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
140                $where = "customer_id = ? AND update_date = ? ";
141                $arrval = array($objCustomer->getValue("customer_id"), $old);
142                //削除
143                $objQuery->delete($table, $where, $arrval);
144                //追加
145                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
146            }
147        */
148        }
149
150        // 規格選択セレクトボックスの作成
151        $this->lfMakeSelect($product_id);
152
153        require_once CLASS_PATH . 'SC_Product.php';
154        $objProduct = new SC_Product($product_id);
155        // 規格1クラス名
156        $this->tpl_class_name1 = $objProduct->className1[$product_id];
157
158        // 規格2クラス名
159        $this->tpl_class_name2 = $objProduct->className2[$product_id];
160       
161        // 規格1
162        $this->arrClassCat1 = $objProduct->classCats1[$product_id];
163
164        // 規格1が設定されている
165        $this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id];
166        // 規格2が設定されている
167        $this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id];
168
169        $this->tpl_stock_find = $objProduct->stock_find[$product_id];
170
171        require_once DATA_PATH . 'module/Services/JSON.php';
172        $objJson = new Services_JSON();
173        $this->tpl_javascript .= 'classCategories = ' . $objJson->encode($objProduct->classCategories[$product_id]) . ';';
174        $this->tpl_javascript .= 'function lnOnLoad(){' . $this->js_lnOnload . '}';
175        $this->tpl_onload .= 'lnOnLoad();';
176
177        // 商品IDをFORM内に保持する。
178        $this->tpl_product_id = $product_id;
179
180        if (!isset($_POST['mode'])) $_POST['mode'] = "";
181        $arrErr = array();
182       
183        switch($_POST['mode']) {
184            case 'cart':
185                // 入力値の変換
186                $this->objFormParam->convParam();
187                $arrErr = $this->lfCheckError();
188                if (count($arrErr) == 0) {
189                    $objCartSess = new SC_CartSession();
190                    $classcategory_id1 = $_POST['classcategory_id1'];
191                    $classcategory_id2 = $_POST['classcategory_id2'];
192
193                    if (!empty($_POST['gmo_oneclick'])) {
194                        $objCartSess->delAllProducts();
195                    }
196
197                    // 規格1が設定されていない場合
198                    if(!$this->tpl_classcat_find1) {
199                        $classcategory_id1 = '0';
200                    }
201
202                    // 規格2が設定されていない場合
203                    if(!$this->tpl_classcat_find2) {
204                        $classcategory_id2 = '0';
205                    }
206
207                    $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
208
209                    if (!empty($_POST['gmo_oneclick'])) {
210                        $objSiteSess = new SC_SiteSession;
211                        $objSiteSess->setRegistFlag();
212                        $objCartSess->saveCurrentCart($objSiteSess->getUniqId());
213
214                        $this->sendRedirect($this->getLocation(
215                            URL_DIR . 'user_data/gmopg_oneclick_confirm.php', array(), true));
216                        exit;
217                    }
218
219                    $this->sendRedirect($this->getLocation(URL_CART_TOP));
220                    exit;
221                }
222                break;
223
224            default:
225                break;
226        }
227        $this->arrErr = $arrErr;
228
229        // DBから商品情報を取得する。
230        $arrRet = $objQuery->select("*, (SELECT count(*) FROM dtb_customer_favorite_products WHERE product_id = alldtl.product_id AND customer_id = ?) AS favorite_count", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($objCustomer->getValue('customer_id'), $product_id));
231        $this->arrProduct = $arrRet[0];
232
233        // 購入制限数を取得
234        if (!SC_Utils_Ex::sfIsInt($this->arrProduct['sale_limit']) || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
235          $this->tpl_sale_limit = SALE_LIMIT_MAX;
236        } else {
237          $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
238        }
239       
240        // サブタイトルを取得
241        $this->tpl_subtitle = $this->arrProduct['name'];
242       
243        // 関連カテゴリを取得
244        $this->arrRelativeCat = $objDb->sfGetMultiCatTree($product_id);
245       
246        // 画像ファイル指定がない場合の置換処理
247        $this->arrProduct['main_image']
248            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
249       
250        $this->lfSetFile();
251        // 支払方法の取得
252        $this->arrPayment = $this->lfGetPayment();
253        // 入力情報を渡す
254        $this->arrForm = $this->objFormParam->getFormParamList();
255        //レビュー情報の取得
256        $this->arrReview = $this->lfGetReviewData($product_id);
257        // トラックバック情報の取得
258
259        // トラックバック機能の稼働状況チェック
260        if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
261            $this->arrTrackbackView = "OFF";
262        } else {
263            $this->arrTrackbackView = "ON";
264            $this->arrTrackback = $this->lfGetTrackbackData($product_id);
265        }
266        $this->trackback_url = TRACKBACK_TO_URL . $product_id;
267        //関連商品情報表示
268        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
269        //この商品を買った人はこんな商品も買っています
270        $this->arrRelateProducts = $this->lfGetRelateProducts($product_id);
271
272        $this->lfConvertParam();
273
274        $objView->assignobj($this);
275        $objView->display(SITE_FRAME);
276    }
277
278    /**
279     * デストラクタ.
280     *
281     * @return void
282     */
283    function destroy() {
284        parent::destroy();
285    }
286
287    /**
288     * モバイルページを初期化する.
289     *
290     * @return void
291     */
292    function mobileInit() {
293        $this->init();
294        $this->tpl_mainpage = "products/detail.tpl";
295    }
296
297    /**
298     * Page のプロセス(モバイル).
299     *
300     * FIXME 要リファクタリング
301     *
302     * @return void
303     */
304    function mobileProcess() {
305        // プロダクトIDの正当性チェック
306        $product_id = $this->lfCheckProductId();
307       
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        // ログイン判定
326        if($objCustomer->isLoginSuccess(true)) {
327            //お気に入りボタン表示
328            $this->tpl_login = true;
329
330            /* 閲覧ログ機能は現在未使用
331
332               $table = "dtb_customer_reading";
333               $where = "customer_id = ? ";
334               $arrval[] = $objCustomer->getValue('customer_id');
335               //顧客の閲覧商品数
336               $rpcnt = $objQuery->count($table, $where, $arrval);
337
338               //閲覧数が設定数以下
339               if ($rpcnt < CUSTOMER_READING_MAX){
340               //閲覧履歴に新規追加
341               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
342               } else {
343               //閲覧履歴の中で一番古いものを削除して新規追加
344               $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
345               $old = $objQuery->getone($oldsql, array($objCustomer->getValue("customer_id")));
346               $where = "customer_id = ? AND update_date = ? ";
347               $arrval = array($objCustomer->getValue("customer_id"), $old);
348               //削除
349               $objQuery->delete($table, $where, $arrval);
350               //追加
351               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
352               }
353            */
354        }
355
356
357        // 規格選択セレクトボックスの作成
358        $this->lfMakeSelectMobile($this, $product_id);
359
360        // 商品IDをFORM内に保持する。
361        $this->tpl_product_id = $product_id;
362
363        switch($_POST['mode']) {
364        case 'select':
365            // 規格1が設定されている場合
366            if($this->tpl_classcat_find1) {
367                // templateの変更
368                $this->tpl_mainpage = "products/select_find1.tpl";
369                break;
370            }
371
372        case 'select2':
373            $this->arrErr = $this->lfCheckError();
374
375            // 規格1が設定されている場合
376            if($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
377                // templateの変更
378                $this->tpl_mainpage = "products/select_find1.tpl";
379                break;
380            }
381
382            // 規格2が設定されている場合
383            if($this->tpl_classcat_find2) {
384                $this->arrErr = array();
385
386                $this->tpl_mainpage = "products/select_find2.tpl";
387                break;
388            }
389
390        case 'selectItem':
391            $this->arrErr = $this->lfCheckError();
392
393            // 規格1が設定されている場合
394            if($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
395                // templateの変更
396                $this->tpl_mainpage = "products/select_find2.tpl";
397                break;
398            }
399            // 商品数の選択を行う
400            $this->tpl_mainpage = "products/select_item.tpl";
401            break;
402
403        case 'cart':
404            // 入力値の変換
405            $this->objFormParam->convParam();
406            $this->arrErr = $this->lfCheckError();
407            if(count($this->arrErr) == 0) {
408                $objCartSess = new SC_CartSession();
409                $classcategory_id1 = $_POST['classcategory_id1'];
410                $classcategory_id2 = $_POST['classcategory_id2'];
411
412                // 規格1が設定されていない場合
413                if(!$this->tpl_classcat_find1) {
414                    $classcategory_id1 = '0';
415                }
416
417                // 規格2が設定されていない場合
418                if(!$this->tpl_classcat_find2) {
419                    $classcategory_id2 = '0';
420                }
421
422                $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
423                $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true);
424                exit;
425            }
426            break;
427
428        default:
429            break;
430        }
431
432        $objQuery = new SC_Query();
433        // DBから商品情報を取得する。
434        $arrRet = $objQuery->select("*", "vw_products_allclass_detail AS alldtl", "product_id = ?", array($product_id));
435        $this->arrProduct = $arrRet[0];
436
437        // 購入制限数を取得
438        if (!SC_Utils_Ex::sfIsInt($this->arrProduct['sale_limit']) || $this->arrProduct['sale_limit'] > SALE_LIMIT_MAX) {
439            $this->tpl_sale_limit = SALE_LIMIT_MAX;
440        } else {
441            $this->tpl_sale_limit = $this->arrProduct['sale_limit'];
442        }
443
444        // サブタイトルを取得
445        $this->tpl_subtitle = $this->arrProduct["name"];
446       
447        // 画像ファイル指定がない場合の置換処理
448        $this->arrProduct['main_image']
449            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
450       
451        // ファイル情報のセット
452        $this->lfSetFile();
453        // 支払方法の取得
454        $this->arrPayment = $this->lfGetPayment();
455        // 入力情報を渡す
456        $this->arrForm = $this->objFormParam->getFormParamList();
457        //レビュー情報の取得
458        $this->arrReview = $this->lfGetReviewData($product_id);
459        // タイトルに商品名を入れる
460        $this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
461        //関連商品情報表示
462        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
463        //この商品を買った人はこんな商品も買っています
464        $this->arrRelateProducts = $this->lfGetRelateProducts($product_id);
465
466        $objView->assignobj($this);
467        $objView->display(SITE_FRAME);
468    }
469
470    /* プロダクトIDの正当性チェック */
471    function lfCheckProductId() {
472        // 管理機能からの確認の場合は、非公開の商品も表示する。
473        if (isset($_GET['admin']) && $_GET['admin'] == 'on') {
474            SC_Utils_Ex::sfIsSuccess(new SC_Session());
475            $status = true;
476            $where = 'del_flg = 0';
477        } else {
478            $status = false;
479            $where = 'del_flg = 0 AND status = 1';
480        }
481
482        if (defined('MOBILE_SITE')) {
483            if (!isset($_POST['mode'])) $_POST['mode'] = "";
484            if (!empty($_POST['mode'])) {
485                $product_id = $_POST['product_id'];
486            } else {
487                $product_id = $_GET['product_id'];
488            }
489        } else {
490            if(isset($_POST['mode']) && $_POST['mode'] != '') {
491                $product_id = $_POST['product_id'];
492            } else {
493                $product_id = $_GET['product_id'];
494            }
495        }
496
497        $objDb = new SC_Helper_DB_Ex();
498        if(!SC_Utils_Ex::sfIsInt($product_id)
499            || SC_Utils_Ex::sfIsZeroFilling($product_id)
500            || !$objDb->sfIsRecord('dtb_products', 'product_id', (array)$product_id, $where))
501            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
502        return $product_id;
503    }
504
505    /* ファイル情報の初期化 */
506    function lfInitFile() {
507        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
508        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
509            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);
510        }
511        $this->objUpFile->addFile("商品比較画像", 'file1', array('jpg'), IMAGE_SIZE, false, NORMAL_IMAGE_HEIGHT, NORMAL_IMAGE_HEIGHT);
512        $this->objUpFile->addFile("商品詳細ファイル", 'file2', array('pdf'), PDF_SIZE, false, 0, 0, false);
513    }
514
515    /* 規格選択セレクトボックスの作成 */
516    function lfMakeSelect() {
517
518        // 選択されている規格
519        $classcategory_id1
520            = isset($_POST['classcategory_id1']) && is_numeric($_POST['classcategory_id1'])
521            ? $_POST['classcategory_id1']
522            : '';
523
524        $classcategory_id2
525            = isset($_POST['classcategory_id2']) && is_numeric($_POST['classcategory_id2'])
526            ? $_POST['classcategory_id2']
527            : '';
528
529        require_once DATA_PATH . 'module/Services/JSON.php';
530        $this->js_lnOnload .= 'fnSetClassCategories('
531            . 'document.form1, '
532            . Services_JSON::encode($classcategory_id2)
533            . '); ';
534    }
535
536    /* 規格選択セレクトボックスの作成
537     * FIXME 要リファクタリング
538     */
539    function lfMakeSelectMobile(&$objPage, $product_id) {
540
541        $objDb = new SC_Helper_DB_Ex();
542        $classcat_find1 = false;
543        $classcat_find2 = false;
544        // 在庫ありの商品の有無
545        $stock_find = false;
546
547        // 規格名一覧
548        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
549        // 規格分類名一覧
550        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
551        // 商品規格情報の取得
552        $arrProductsClass = $this->lfGetProductsClass($product_id);
553
554        // 規格1クラス名の取得
555        $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
556        // 規格2クラス名の取得
557        $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
558
559        // すべての組み合わせ数
560        $count = count($arrProductsClass);
561
562        $classcat_id1 = "";
563
564        $arrSele1 = array();
565        $arrSele2 = array();
566
567        for ($i = 0; $i < $count; $i++) {
568            // 在庫のチェック
569            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
570                continue;
571            }
572
573            $stock_find = true;
574
575            // 規格1のセレクトボックス用
576            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
577                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
578                $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
579            }
580
581            // 規格2のセレクトボックス用
582            if($arrProductsClass[$i]['classcategory_id1'] == $_POST['classcategory_id1'] and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
583                $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
584                $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
585            }
586        }
587
588        // 規格1
589        $objPage->arrClassCat1 = $arrSele1;
590        $objPage->arrClassCat2 = $arrSele2;
591
592        // 規格1が設定されている
593        if($arrProductsClass[0]['classcategory_id1'] != '0') {
594            $classcat_find1 = true;
595        }
596
597        // 規格2が設定されている
598        if($arrProductsClass[0]['classcategory_id2'] != '0') {
599            $classcat_find2 = true;
600        }
601
602        $objPage->tpl_classcat_find1 = $classcat_find1;
603        $objPage->tpl_classcat_find2 = $classcat_find2;
604        $objPage->tpl_stock_find = $stock_find;
605    }
606
607    /* パラメータ情報の初期化 */
608    function lfInitParam() {
609        $this->objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
610        $this->objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
611        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
612    }
613
614    /* 商品規格情報の取得 */
615    function lfGetProductsClass($product_id) {
616        $arrRet = array();
617        if(SC_Utils_Ex::sfIsInt($product_id)) {
618            // 商品規格取得
619            $objQuery = new SC_Query();
620            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
621            $table = "vw_product_class AS prdcls";
622            $where = "product_id = ?";
623            $objQuery->setorder("rank1 DESC, rank2 DESC");
624            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
625        }
626        return $arrRet;
627    }
628
629    /* 登録済み関連商品の読み込み */
630    function lfPreGetRecommendProducts($product_id) {
631        $arrRecommend = array();
632        $objQuery = new SC_Query();
633        $objQuery->setorder("rank DESC");
634        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
635        $max = count($arrRet);
636        $no = 0;
637        $from = "vw_products_allclass AS T1 "
638                . " JOIN ("
639                . " SELECT max(T2.rank) AS product_rank, "
640                . "        T2.product_id"
641                . "   FROM dtb_product_categories T2  "
642                . " GROUP BY product_id) AS T3 USING (product_id)";
643        $objQuery->setorder("T3.product_rank DESC");
644        for($i = 0; $i < $max; $i++) {
645            $where = "del_flg = 0 AND T3.product_id = ? AND status = 1";
646            $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']));
647
648            if(count($arrProductInfo) > 0) {
649                $arrRecommend[$no] = $arrProductInfo[0];
650                $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
651                $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
652                $no++;
653            }
654        }
655        return $arrRecommend;
656    }
657
658    /* 入力内容のチェック */
659    function lfCheckError() {
660        if ($_POST['mode'] == "add_favorite") {
661            $objCustomer = new SC_Customer();
662            $objErr = new SC_CheckError();
663            $customer_id = $objCustomer->getValue('customer_id');
664            if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
665                $objErr->arrErr['add_favorite'.$favorite_product_id] = "※ この商品は既にお気に入りに追加されています。<br />";
666            }
667        } else {
668            // 入力データを渡す。
669            $arrRet =  $this->objFormParam->getHashArray();
670            $objErr = new SC_CheckError($arrRet);
671            $objErr->arrErr = $this->objFormParam->checkError();
672
673            // 複数項目チェック
674            if ($this->tpl_classcat_find1) {
675                $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
676            }
677            if ($this->tpl_classcat_find2) {
678                $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
679            }
680        }
681
682        return $objErr->arrErr;
683    }
684
685    //閲覧履歴新規登録
686    function lfRegistReadingData($product_id, $customer_id){
687        $objQuery = new SC_Query;
688        $sqlval['customer_id'] = $customer_id;
689        $sqlval['reading_product_id'] = $product_id;
690        $sqlval['create_date'] = 'NOW()';
691        $sqlval['update_date'] = 'NOW()';
692        $objQuery->insert("dtb_customer_reading", $sqlval);
693    }
694
695    //この商品を買った人はこんな商品も買っています FIXME
696    function lfGetRelateProducts($product_id) {
697        $objQuery = new SC_Query;
698        //自動抽出
699        $objQuery->setorder("random()");
700        //表示件数の制限
701        $objQuery->setlimit(RELATED_PRODUCTS_MAX);
702        //検索条件
703        $col = "name, main_list_image, price01_min, price02_min, price01_max, price02_max, point_rate";
704        $from = "vw_products_allclass AS allcls ";
705        $where = "del_flg = 0 AND status = 1 AND (stock_max <> 0 OR stock_max IS NULL) AND product_id = ? ";
706        $arrval[] = $product_id;
707        //結果の取得
708        $arrProducts = $objQuery->select($col, $from, $where, $arrval);
709
710        return $arrProducts;
711    }
712
713    //商品ごとのレビュー情報を取得する
714    function lfGetReviewData($id) {
715        $objQuery = new SC_Query;
716        //商品ごとのレビュー情報を取得する
717        $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
718        $from = "dtb_review";
719        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
720        $arrval[] = $id;
721        $arrReview = $objQuery->select($col, $from, $where, $arrval);
722        return $arrReview;
723    }
724
725    /*
726     * 商品ごとのトラックバック情報を取得する
727     *
728     * @param $product_id
729     * @return $arrTrackback
730     */
731    function lfGetTrackbackData($product_id) {
732
733        $arrTrackback = array();
734
735        $objQuery = new SC_Query;
736        //商品ごとのトラックバック情報を取得する
737        $col = "blog_name, url, title, excerpt, title, create_date";
738        $from = "dtb_trackback";
739        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
740        $arrval[] = $product_id;
741        $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
742        return $arrTrackback;
743    }
744
745    //支払方法の取得
746    //payment_id    1:クレジット 2:ショッピングローン
747    function lfGetPayment() {
748        $objQuery = new SC_Query;
749        $col = "payment_id, rule, payment_method";
750        $from = "dtb_payment";
751        $where = "del_flg = 0";
752        $order = "payment_id";
753        $objQuery->setorder($order);
754        $arrRet = $objQuery->select($col, $from, $where);
755        return $arrRet;
756    }
757
758    function lfConvertParam() {
759        if (!isset($this->arrForm['quantity']['value'])) $this->arrForm['quantity']['value'] = "";
760        $value = $this->arrForm['quantity']['value'];
761        $this->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
762    }
763
764    /*
765     * ファイルの情報をセットする
766     *
767     */
768    function lfSetFile() {
769        // DBからのデータを引き継ぐ
770        $this->objUpFile->setDBFileList($this->arrProduct);
771        // ファイル表示用配列を渡す
772        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
773
774        // サブ画像の有無を判定
775        $this->subImageFlag = false;
776        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
777            if ($this->arrFile["sub_image" . $i]["filepath"] != "") {
778                $this->subImageFlag = true;
779            }
780        }
781    }
782
783    /*
784     * お気に入り商品登録
785     */
786    function lfRegistFavoriteProduct($customer_id, $product_id) {
787        $objQuery = new SC_Query();
788        $objConn = new SC_DbConn();
789        $count = $objConn->getOne("SELECT COUNT(*) FROM dtb_customer_favorite_products WHERE customer_id = ? AND product_id = ?", array($customer_id, $product_id));
790
791        if ($count == 0) {
792            $sqlval['customer_id'] = $customer_id;
793            $sqlval['product_id'] = $product_id;
794            $sqlval['update_date'] = "now()";
795            $sqlval['create_date'] = "now()";
796
797            $objQuery->begin();
798            $objQuery->insert('dtb_customer_favorite_products', $sqlval);
799            $objQuery->commit();
800        }
801    }
802
803}
804?>
Note: See TracBrowser for help on using the repository browser.