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

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