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

Revision 18290, 31.3 KB checked in by Seasoft, 15 years ago (diff)

商品詳細で「前頁のURLを記録しておく」が意図せず呼ばれているのを修正。

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