source: branches/camp/camp-2_5-C/data/class/pages/admin/products/LC_Page_Admin_Products_Preview.php @ 19656

Revision 19656, 30.5 KB checked in by kishik, 13 years ago (diff)

商品登録前プレビュー

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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_Admin_Products_Preview 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        $this->tpl_mainpage = "detail.tpl";
74    }
75
76    /**
77     * Page のプロセス.
78     *
79     * @return void
80     */
81    function process() {
82        // プロダクトIDの正当性チェック
83        // $product_id = $this->lfCheckProductId();
84       
85        $this->arrProduct = $_SESSION["preview"];
86        var_dump($this->arrProduct);
87       
88        // マッピング
89        $product_id = $this->arrProduct["product_id"];
90        $this->arrFile["main_image"]["filepath"] = IMAGE_SAVE_URL . $this->arrProduct["save_main_image"];
91        $objProduct = new SC_Product();
92        ////////////////////////////////////
93        // 本来はフォームの入力データから取ってくるべき
94        ////////////////////////////////////
95        $this->arrProduct = $objProduct->getDetail($product_id);
96
97        ////////////////////////////////////
98        // 以下未検証(全く不要なものも多数)
99        ////////////////////////////////////
100
101
102        $objView = new SC_SiteView(strlen($_POST['mode']) == 0);
103        $objCustomer = new SC_Customer();
104        $objQuery = new SC_Query();
105        $objDb = new SC_Helper_DB_Ex();
106
107        // レイアウトデザインを取得
108        $helper = new SC_Helper_PageLayout_Ex();
109        $helper->sfGetPageLayout($this, false, "products/detail.php");
110
111        // ログイン中のユーザが商品をお気に入りにいれる処理
112        if ($objCustomer->isLoginSuccess() === true && strlen($_POST['mode']) > 0 && $_POST['mode'] == "add_favorite" && strlen($_POST['favorite_product_id']) > 0 ) {
113            // 値の正当性チェック
114            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")) {
115                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
116                exit;
117            } else {
118                $this->arrErr = $this->lfCheckError();
119                if(count($this->arrErr) == 0) {
120                    $customer_id = $objCustomer->getValue('customer_id');
121                    $this->lfRegistFavoriteProduct($customer_id, $_POST['favorite_product_id']);
122                }
123            }
124        }
125
126        // パラメータ管理クラス
127        $this->objFormParam = new SC_FormParam();
128        // パラメータ情報の初期化
129        $this->lfInitParam();
130        // POST値の取得
131        $this->objFormParam->setParam($_SESSION['preview']);
132
133        // ファイル管理クラス
134        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
135        // ファイル情報の初期化
136        $this->lfInitFile();
137
138        // ログイン判定
139        if ($objCustomer->isLoginSuccess() === true) {
140            //お気に入りボタン表示
141            $this->tpl_login = true;
142
143        /* 閲覧ログ機能は現在未使用
144
145            $table = "dtb_customer_reading";
146            $where = "customer_id = ? ";
147            $arrval[] = $objCustomer->getValue('customer_id');
148            //顧客の閲覧商品数
149            $rpcnt = $objQuery->count($table, $where, $arrval);
150
151            //閲覧数が設定数以下
152            if ($rpcnt < CUSTOMER_READING_MAX){
153                //閲覧履歴に新規追加
154                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
155            } else {
156                //閲覧履歴の中で一番古いものを削除して新規追加
157                $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
158                $old = $objQuery->getOne($oldsql, array($objCustomer->getValue("customer_id")));
159                $where = "customer_id = ? AND update_date = ? ";
160                $arrval = array($objCustomer->getValue("customer_id"), $old);
161                //削除
162                $objQuery->delete($table, $where, $arrval);
163                //追加
164                lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
165            }
166        */
167        }
168
169        // 規格選択セレクトボックスの作成
170        $this->lfMakeSelect($product_id);
171
172        $objProduct = new SC_Product();
173        $objProduct->setProductsClassByProductIds(array($product_id));
174
175        // 規格1クラス名
176        $this->tpl_class_name1 = $objProduct->className1[$product_id];
177
178        // 規格2クラス名
179        $this->tpl_class_name2 = $objProduct->className2[$product_id];
180
181        // 規格1
182        $this->arrClassCat1 = $objProduct->classCats1[$product_id];
183
184        // 規格1が設定されている
185        $this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id];
186        // 規格2が設定されている
187        $this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id];
188
189        $this->tpl_stock_find = $objProduct->stock_find[$product_id];
190        $this->tpl_product_class_id = $objProduct->classCategories[$product_id]['']['']['product_class_id'];
191        $this->tpl_product_type = $objProduct->classCategories[$product_id]['']['']['product_type'];
192
193        require_once DATA_PATH . 'module/Services/JSON.php';
194        $objJson = new Services_JSON();
195        $this->tpl_javascript .= 'classCategories = ' . $objJson->encode($objProduct->classCategories[$product_id]) . ';';
196        $this->tpl_javascript .= 'function lnOnLoad(){' . $this->js_lnOnload . '}';
197        $this->tpl_onload .= 'lnOnLoad();';
198
199        // 商品IDをFORM内に保持する。
200        $this->tpl_product_id = $product_id;
201
202        if (!isset($_POST['mode'])) $_POST['mode'] = "";
203        $arrErr = array();
204
205        switch($_POST['mode']) {
206            case 'cart':
207                // 入力値の変換
208                $this->objFormParam->convParam();
209                $arrErr = $this->lfCheckError();
210                if (count($arrErr) == 0) {
211                    $objCartSess = new SC_CartSession();
212                    $classcategory_id1 = $_POST['classcategory_id1'];
213                    $classcategory_id2 = $_POST['classcategory_id2'];
214                    $product_class_id = $_POST['product_class_id'];
215                    $product_type = $_POST['product_type'];
216
217                    if (!empty($_POST['gmo_oneclick'])) {
218                        $objCartSess->delAllProducts();
219                    }
220
221                    // 規格1が設定されていない場合
222                    if(!$this->tpl_classcat_find1) {
223                        $classcategory_id1 = '0';
224                    }
225
226                    // 規格2が設定されていない場合
227                    if(!$this->tpl_classcat_find2) {
228                        $classcategory_id2 = '0';
229                    }
230                    $objCartSess->addProduct($product_class_id, $this->objFormParam->getValue('quantity'), $product_type);
231
232                    if (!empty($_POST['gmo_oneclick'])) {
233                        $objSiteSess = new SC_SiteSession;
234                        $objSiteSess->setRegistFlag();
235                        $objCartSess->saveCurrentCart($objSiteSess->getUniqId());
236
237                        $this->sendRedirect($this->getLocation(
238                            URL_DIR . 'user_data/gmopg_oneclick_confirm.php', array(), true));
239                        exit;
240                    }
241
242                    $this->sendRedirect($this->getLocation(URL_CART_TOP));
243                    exit;
244                }
245                break;
246
247            default:
248                break;
249        }
250        $this->arrErr = $arrErr;
251
252        // 商品詳細を取得
253        //$this->arrProduct = $objProduct->getDetail($product_id);
254
255        // サブタイトルを取得
256        $this->tpl_subtitle = $this->arrProduct['name'];
257
258        // 関連カテゴリを取得
259        $this->arrRelativeCat = $objDb->sfGetMultiCatTree($product_id);
260        ////
261
262        // 商品ステータスを取得
263        // FIX!
264        // $this->productStatus = $objProduct->getProductStatus($product_id);
265
266        // 画像ファイル指定がない場合の置換処理
267        $this->arrProduct['main_image']
268            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
269
270        // $this->lfSetFile();
271        // 支払方法の取得
272        $this->arrPayment = $this->lfGetPayment();
273        // 入力情報を渡す
274        $this->arrForm = $this->objFormParam->getFormParamList();
275        //レビュー情報の取得
276        $this->arrReview = $this->lfGetReviewData($product_id);
277        // トラックバック情報の取得
278
279        // トラックバック機能の稼働状況チェック
280        if (SC_Utils_Ex::sfGetSiteControlFlg(SITE_CONTROL_TRACKBACK) != 1) {
281            $this->arrTrackbackView = "OFF";
282        } else {
283            $this->arrTrackbackView = "ON";
284            $this->arrTrackback = $this->lfGetTrackbackData($product_id);
285        }
286        $this->trackback_url = TRACKBACK_TO_URL . $product_id;
287        //関連商品情報表示
288        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
289
290        $this->lfConvertParam();
291
292        $objView->assignobj($this);
293        $objView->display(SITE_FRAME);
294    }
295
296    /**
297     * デストラクタ.
298     *
299     * @return void
300     */
301    function destroy() {
302        parent::destroy();
303    }
304
305    /**
306     * モバイルページを初期化する.
307     *
308     * @return void
309     */
310    function mobileInit() {
311        $this->init();
312        $this->tpl_mainpage = "products/detail.tpl";
313    }
314
315    /**
316     * Page のプロセス(モバイル).
317     *
318     * FIXME 要リファクタリング
319     *
320     * @return void
321     */
322    function mobileProcess() {
323        // プロダクトIDの正当性チェック
324        $product_id = $this->lfCheckProductId();
325
326        $objView = new SC_MobileView();
327        $objCustomer = new SC_Customer();
328        $objQuery = new SC_Query();
329        $objDb = new SC_Helper_DB_Ex();
330
331        // パラメータ管理クラス
332        $this->objFormParam = new SC_FormParam();
333        // パラメータ情報の初期化
334        $this->lfInitParam();
335        // POST値の取得
336        $this->objFormParam->setParam($_POST);
337
338        // ファイル管理クラス
339        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
340        // ファイル情報の初期化
341        $this->lfInitFile();
342
343        // ログイン判定
344        if($objCustomer->isLoginSuccess(true)) {
345            //お気に入りボタン表示
346            $this->tpl_login = true;
347
348            /* 閲覧ログ機能は現在未使用
349
350               $table = "dtb_customer_reading";
351               $where = "customer_id = ? ";
352               $arrval[] = $objCustomer->getValue('customer_id');
353               //顧客の閲覧商品数
354               $rpcnt = $objQuery->count($table, $where, $arrval);
355
356               //閲覧数が設定数以下
357               if ($rpcnt < CUSTOMER_READING_MAX){
358               //閲覧履歴に新規追加
359               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
360               } else {
361               //閲覧履歴の中で一番古いものを削除して新規追加
362               $oldsql = "SELECT MIN(update_date) FROM ".$table." WHERE customer_id = ?";
363               $old = $objQuery->getOne($oldsql, array($objCustomer->getValue("customer_id")));
364               $where = "customer_id = ? AND update_date = ? ";
365               $arrval = array($objCustomer->getValue("customer_id"), $old);
366               //削除
367               $objQuery->delete($table, $where, $arrval);
368               //追加
369               lfRegistReadingData($product_id, $objCustomer->getValue('customer_id'));
370               }
371            */
372        }
373
374
375        // 規格選択セレクトボックスの作成
376        $this->lfMakeSelectMobile($this, $product_id);
377
378        // 商品IDをFORM内に保持する。
379        $this->tpl_product_id = $product_id;
380
381        switch($_POST['mode']) {
382        case 'select':
383            // 規格1が設定されている場合
384            if($this->tpl_classcat_find1) {
385                // templateの変更
386                $this->tpl_mainpage = "products/select_find1.tpl";
387                break;
388            }
389
390        case 'select2':
391            $this->arrErr = $this->lfCheckError();
392
393            // 規格1が設定されている場合
394            if($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
395                // templateの変更
396                $this->tpl_mainpage = "products/select_find1.tpl";
397                break;
398            }
399
400            // 規格2が設定されている場合
401            if($this->tpl_classcat_find2) {
402                $this->arrErr = array();
403
404                $this->tpl_mainpage = "products/select_find2.tpl";
405                break;
406            }
407
408        case 'selectItem':
409            $this->arrErr = $this->lfCheckError();
410
411            // 規格1が設定されている場合
412            if($this->tpl_classcat_find2 and $this->arrErr['classcategory_id2']) {
413                // templateの変更
414                $this->tpl_mainpage = "products/select_find2.tpl";
415                break;
416            }
417            // 商品数の選択を行う
418            $this->tpl_mainpage = "products/select_item.tpl";
419            break;
420
421        case 'cart':
422            // 入力値の変換
423            $this->objFormParam->convParam();
424            $this->arrErr = $this->lfCheckError();
425            if(count($this->arrErr) == 0) {
426                $objCartSess = new SC_CartSession();
427                $product_class_id = $_POST['product_class_id'];
428                $classcategory_id1 = $_POST['classcategory_id1'];
429                $classcategory_id2 = $_POST['classcategory_id2'];
430
431                // 規格1が設定されていない場合
432                if(!$this->tpl_classcat_find1) {
433                    $classcategory_id1 = '0';
434                }
435
436                // 規格2が設定されていない場合
437                if(!$this->tpl_classcat_find2) {
438                    $classcategory_id2 = '0';
439                }
440
441                $objCartSess->addProduct(array($_POST['product_id'], $product_class_id, $classcategory_id1, $classcategory_id2), $this->objFormParam->getValue('quantity'));
442                $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true);
443                exit;
444            }
445            break;
446
447        default:
448            break;
449        }
450
451        // 商品詳細を取得
452        $objProduct = new SC_Product();
453        $this->arrProduct = $objProduct->getDetail($product_id);
454
455        // サブタイトルを取得
456        $this->tpl_subtitle = $this->arrProduct["name"];
457
458        // 画像ファイル指定がない場合の置換処理
459        $this->arrProduct['main_image']
460            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
461
462        // ファイル情報のセット
463        $this->lfSetFile();
464        // 支払方法の取得
465        $this->arrPayment = $this->lfGetPayment();
466        // 入力情報を渡す
467        $this->arrForm = $this->objFormParam->getFormParamList();
468        //レビュー情報の取得
469        $this->arrReview = $this->lfGetReviewData($product_id);
470        // タイトルに商品名を入れる
471        $this->tpl_title = "商品詳細 ". $this->arrProduct["name"];
472        //関連商品情報表示
473        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
474
475        $objView->assignobj($this);
476        $objView->display(SITE_FRAME);
477    }
478
479    /* プロダクトIDの正当性チェック */
480    function lfCheckProductId() {
481        // 管理機能からの確認の場合は、非公開の商品も表示する。
482        if (isset($_GET['admin']) && $_GET['admin'] == 'on') {
483            SC_Utils_Ex::sfIsSuccess(new SC_Session());
484            $status = true;
485            $where = 'del_flg = 0';
486        } else {
487            $status = false;
488            $where = 'del_flg = 0 AND status = 1';
489        }
490
491        if (defined('MOBILE_SITE')) {
492            if (!isset($_POST['mode'])) $_POST['mode'] = "";
493            if (!empty($_POST['mode'])) {
494                $product_id = $_POST['product_id'];
495            } else {
496                $product_id = $_GET['product_id'];
497            }
498        } else {
499            if(isset($_POST['mode']) && $_POST['mode'] != '') {
500                $product_id = $_POST['product_id'];
501            } else {
502                $product_id = $_GET['product_id'];
503            }
504        }
505
506        $objDb = new SC_Helper_DB_Ex();
507        if(!SC_Utils_Ex::sfIsInt($product_id)
508            || SC_Utils_Ex::sfIsZeroFilling($product_id)
509            || !$objDb->sfIsRecord('dtb_products', 'product_id', (array)$product_id, $where))
510            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
511        return $product_id;
512    }
513
514    /* ファイル情報の初期化 */
515    function lfInitFile() {
516        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg'), IMAGE_SIZE, true, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
517        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
518            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_HEIGHT, NORMAL_SUBIMAGE_HEIGHT);
519        }
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         * FIXME
560         * パフォーマンスが出ないため,
561         * SC_Product::getProductsClassByProductIds() を使用した実装に変更
562         */
563        // 商品規格情報の取得
564        $arrProductsClass = $this->lfGetProductsClass($product_id);
565
566        // 規格1クラス名の取得
567        $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
568        // 規格2クラス名の取得
569        $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
570
571        // すべての組み合わせ数
572        $count = count($arrProductsClass);
573
574        $classcat_id1 = "";
575
576        $arrSele1 = array();
577        $arrSele2 = array();
578
579        for ($i = 0; $i < $count; $i++) {
580            // 在庫のチェック
581            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
582                continue;
583            }
584
585            $stock_find = true;
586
587            // 規格1のセレクトボックス用
588            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
589                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
590                $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
591            }
592
593            // 規格2のセレクトボックス用
594            if($arrProductsClass[$i]['classcategory_id1'] == $_POST['classcategory_id1'] and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
595                $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
596                $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
597            }
598        }
599
600        // 規格1
601        $objPage->arrClassCat1 = $arrSele1;
602        $objPage->arrClassCat2 = $arrSele2;
603
604        // 規格1が設定されている
605        if($arrProductsClass[0]['classcategory_id1'] != '0') {
606            $classcat_find1 = true;
607        }
608
609        // 規格2が設定されている
610        if($arrProductsClass[0]['classcategory_id2'] != '0') {
611            $classcat_find2 = true;
612        }
613
614        $objPage->tpl_classcat_find1 = $classcat_find1;
615        $objPage->tpl_classcat_find2 = $classcat_find2;
616        $objPage->tpl_stock_find = $stock_find;
617    }
618
619    /* パラメータ情報の初期化 */
620    function lfInitParam() {
621        $this->objFormParam->addParam("規格1", "classcategory_id1", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
622        $this->objFormParam->addParam("規格2", "classcategory_id2", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
623        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
624    }
625
626    /* 商品規格情報の取得 */
627    function lfGetProductsClass($product_id) {
628        $arrRet = array();
629        if(SC_Utils_Ex::sfIsInt($product_id)) {
630            // 商品規格取得
631            $objQuery = new SC_Query();
632            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
633            $table = "vw_product_class AS prdcls";
634            $where = "product_id = ?";
635            $objQuery->setOrder("rank1 DESC, rank2 DESC");
636            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
637        }
638        return $arrRet;
639    }
640
641    /* 登録済み関連商品の読み込み */
642    function lfPreGetRecommendProducts($product_id) {
643        $arrRecommend = array();
644        $objQuery = new SC_Query();
645        $objQuery->setOrder("rank DESC");
646        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
647        $max = count($arrRet);
648        $no = 0;
649        // FIXME SC_Product クラスを使用した実装
650        $from = "vw_products_allclass AS T1 "
651                . " JOIN ("
652                . " SELECT max(T2.rank) AS product_rank, "
653                . "        T2.product_id"
654                . "   FROM dtb_product_categories T2  "
655                . " GROUP BY product_id) AS T3 USING (product_id)";
656        $objQuery->setOrder("T3.product_rank DESC");
657        for($i = 0; $i < $max; $i++) {
658            $where = "del_flg = 0 AND T3.product_id = ? AND status = 1";
659            $arrProductInfo = $objQuery->select("DISTINCT main_list_image, price02_min, price02_max, price01_min, price01_max, name, T3.product_rank", $from, $where, array($arrRet[$i]['recommend_product_id']));
660
661            if(count($arrProductInfo) > 0) {
662                $arrRecommend[$no] = $arrProductInfo[0];
663                $arrRecommend[$no]['product_id'] = $arrRet[$i]['recommend_product_id'];
664                $arrRecommend[$no]['comment'] = $arrRet[$i]['comment'];
665                $no++;
666            }
667        }
668        return $arrRecommend;
669    }
670
671    /* 入力内容のチェック */
672    function lfCheckError() {
673        if ($_POST['mode'] == "add_favorite") {
674            $objCustomer = new SC_Customer();
675            $objErr = new SC_CheckError();
676            $customer_id = $objCustomer->getValue('customer_id');
677            if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
678                $objErr->arrErr['add_favorite'.$favorite_product_id] = "※ この商品は既にお気に入りに追加されています。<br />";
679            }
680        } else {
681            // 入力データを渡す。
682            $arrRet =  $this->objFormParam->getHashArray();
683            $objErr = new SC_CheckError($arrRet);
684            $objErr->arrErr = $this->objFormParam->checkError();
685
686            // 複数項目チェック
687            if ($this->tpl_classcat_find1) {
688                $objErr->doFunc(array("規格1", "classcategory_id1"), array("EXIST_CHECK"));
689            }
690            if ($this->tpl_classcat_find2) {
691                $objErr->doFunc(array("規格2", "classcategory_id2"), array("EXIST_CHECK"));
692            }
693        }
694
695        return $objErr->arrErr;
696    }
697
698    //閲覧履歴新規登録
699    function lfRegistReadingData($product_id, $customer_id){
700        $objQuery = new SC_Query;
701        $sqlval['customer_id'] = $customer_id;
702        $sqlval['reading_product_id'] = $product_id;
703        $sqlval['create_date'] = 'NOW()';
704        $sqlval['update_date'] = 'NOW()';
705        $objQuery->insert("dtb_customer_reading", $sqlval);
706    }
707
708    //商品ごとのレビュー情報を取得する
709    function lfGetReviewData($id) {
710        $objQuery = new SC_Query;
711        //商品ごとのレビュー情報を取得する
712        $col = "create_date, reviewer_url, reviewer_name, recommend_level, title, comment";
713        $from = "dtb_review";
714        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . REVIEW_REGIST_MAX;
715        $arrval[] = $id;
716        $arrReview = $objQuery->select($col, $from, $where, $arrval);
717        return $arrReview;
718    }
719
720    /*
721     * 商品ごとのトラックバック情報を取得する
722     *
723     * @param $product_id
724     * @return $arrTrackback
725     */
726    function lfGetTrackbackData($product_id) {
727
728        $arrTrackback = array();
729
730        $objQuery = new SC_Query;
731        //商品ごとのトラックバック情報を取得する
732        $col = "blog_name, url, title, excerpt, title, create_date";
733        $from = "dtb_trackback";
734        $where = "del_flg = 0 AND status = 1 AND product_id = ? ORDER BY create_date DESC LIMIT " . TRACKBACK_VIEW_MAX;
735        $arrval[] = $product_id;
736        $arrTrackback = $objQuery->select($col, $from, $where, $arrval);
737        return $arrTrackback;
738    }
739
740    //支払方法の取得
741    //payment_id    1:クレジット 2:ショッピングローン
742    function lfGetPayment() {
743        $objQuery = new SC_Query;
744        $col = "payment_id, rule, payment_method";
745        $from = "dtb_payment";
746        $where = "del_flg = 0";
747        $order = "payment_id";
748        $objQuery->setOrder($order);
749        $arrRet = $objQuery->select($col, $from, $where);
750        return $arrRet;
751    }
752
753    function lfConvertParam() {
754        if (!isset($this->arrForm['quantity']['value'])) $this->arrForm['quantity']['value'] = "";
755        $value = $this->arrForm['quantity']['value'];
756        $this->arrForm['quantity']['value'] = htmlspecialchars($value, ENT_QUOTES, CHAR_CODE);
757    }
758
759    /*
760     * ファイルの情報をセットする
761     *
762     */
763    function lfSetFile() {
764        // DBからのデータを引き継ぐ
765        $this->objUpFile->setDBFileList($this->arrProduct);
766        // ファイル表示用配列を渡す
767        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL, true);
768
769        // サブ画像の有無を判定
770        $this->subImageFlag = false;
771        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
772            if ($this->arrFile["sub_image" . $i]["filepath"] != "") {
773                $this->subImageFlag = true;
774            }
775        }
776    }
777
778    /*
779     * お気に入り商品登録
780     */
781    function lfRegistFavoriteProduct($customer_id, $product_id) {
782        $objQuery = new SC_Query();
783        $count = $objQuery->count("dtb_customer_favorite_products", "customer_id = ? AND product_id = ?", array($customer_id, $product_id));
784
785        if ($count == 0) {
786            $sqlval['customer_id'] = $customer_id;
787            $sqlval['product_id'] = $product_id;
788            $sqlval['update_date'] = "now()";
789            $sqlval['create_date'] = "now()";
790
791            $objQuery->begin();
792            $objQuery->insert('dtb_customer_favorite_products', $sqlval);
793            $objQuery->commit();
794        }
795    }
796
797}
798?>
Note: See TracBrowser for help on using the repository browser.