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

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