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

Revision 17425, 33.9 KB checked in by Seasoft, 16 years ago (diff)

管理機能の表示名称を統一。
 http://xoops.ec-cube.net/modules/newbb/viewtopic.php?topic_id=2473&forum=4

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