source: branches/version-2_13-dev/data/class/pages/products/LC_Page_Products_Detail.php @ 23458

Revision 23458, 27.6 KB checked in by pineray, 10 years ago (diff)

#2515 無駄な処理を改善する for 2.13.3

LC_Page_Products_Detail での関連カテゴリーの取得を、SC_Helper_Category を使った形に変更.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26if (file_exists(MODULE_REALDIR . 'mdl_gmopg/inc/function.php')) {
27    require_once MODULE_REALDIR . 'mdl_gmopg/inc/function.php';
28}
29/**
30 * 商品詳細 のページクラス.
31 *
32 * @package Page
33 * @author LOCKON CO.,LTD.
34 * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $
35 */
36class LC_Page_Products_Detail extends LC_Page_Ex
37{
38    /** 商品ステータス */
39    public $arrSTATUS;
40
41    /** 商品ステータス画像 */
42    public $arrSTATUS_IMAGE;
43
44    /** 発送予定日 */
45    public $arrDELIVERYDATE;
46
47    /** おすすめレベル */
48    public $arrRECOMMEND;
49
50    /** @var SC_FormParam フォームパラメーター */
51    public $objFormParam;
52
53    /** @var SC_UploadFile アップロードファイル */
54    public $objUpFile;
55
56    /** @var string モード */
57    public $mode;
58
59    /** @var array 商品情報 */
60    public $arrProduct;
61
62    /** @var string 規格1クラス名 */
63    public $tpl_class_name1;
64
65    /** @var string 規格2クラス名 */
66    public $tpl_class_name2;
67
68    /** @var bool 在庫があるかどうか */
69    public $tpl_stock_find;
70
71    /** @var array 規格1の規格分類 */
72    public $arrClassCat1;
73
74    /** @var bool 規格1が設定されている */
75    public $tpl_classcat_find1;
76
77    /** @var bool 規格2が設定されている */
78    public $tpl_classcat_find2;
79
80    /** @var int デフォルトの商品規格ID */
81    public $tpl_product_class_id;
82
83    /** @var int デフォルトの商品タイプ */
84    public $tpl_product_type;
85
86    /** @var string ページ表示時に実行するJavaScript */
87    public $js_lnOnload;
88
89    /** @var int 商品ID */
90    public $tpl_product_id;
91
92    /** @var array フォーム情報 */
93    public $arrForm;
94
95    /** @var string サブタイトル */
96    public $tpl_subtitle;
97
98    /** @var array 関連カテゴリー */
99    public $arrRelativeCat;
100
101    /** @var array 商品ステータス(アイコン) */
102    public $productStatus;
103
104    /** @var bool サブ画像が存在するか */
105    public $subImageFlag;
106
107    /** @var array レビュー情報 */
108    public $arrReview;
109
110    /** @var array 関連商品情報 */
111    public $arrRecommend;
112
113    /** @var array ファイル情報 */
114    public $arrFile;
115
116    /** @var bool ログイン状態かどうか */
117    public $tpl_login;
118
119    /** @var bool お気に入りに登録済みか */
120    public $is_favorite;
121
122    /** @var bool お気に入りに登録したことを示すフラグ */
123    public $just_added_favorite;
124
125    /** @var array エラー情報 */
126    public $arrErr;
127
128    /**
129     * Page を初期化する.
130     *
131     * @return void
132     */
133    public function init()
134    {
135        parent::init();
136        $masterData = new SC_DB_MasterData_Ex();
137        $this->arrSTATUS = $masterData->getMasterData('mtb_status');
138        $this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image');
139        $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date');
140        $this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend');
141
142        // POST に限定する mode
143        $this->arrLimitPostMode[] = 'cart';
144        $this->arrLimitPostMode[] = 'add_favorite';
145        $this->arrLimitPostMode[] = 'add_favorite_sphone';
146        $this->arrLimitPostMode[] = 'select';
147        $this->arrLimitPostMode[] = 'select2';
148        $this->arrLimitPostMode[] = 'selectItem';
149    }
150
151    /**
152     * Page のプロセス.
153     *
154     * @return void
155     */
156    public function process()
157    {
158        parent::process();
159        $this->action();
160        $this->sendResponse();
161    }
162
163    /**
164     * Page のAction.
165     *
166     * @return void
167     */
168    public function action()
169    {
170        //決済処理中ステータスのロールバック
171        $objPurchase = new SC_Helper_Purchase_Ex();
172        $objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG);
173
174        // 会員クラス
175        $objCustomer = new SC_Customer_Ex();
176
177        // パラメーター管理クラス
178        $this->objFormParam = new SC_FormParam_Ex();
179        // パラメーター情報の初期化
180        $this->arrForm = $this->lfInitParam($this->objFormParam);
181        // ファイル管理クラス
182        $this->objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
183        // ファイル情報の初期化
184        $this->objUpFile = $this->lfInitFile($this->objUpFile);
185
186        // プロダクトIDの正当性チェック
187        $product_id = $this->lfCheckProductId($this->objFormParam->getValue('admin'), $this->objFormParam->getValue('product_id'));
188        $this->mode = $this->getMode();
189
190        $objProduct = new SC_Product_Ex();
191        $objProduct->setProductsClassByProductIds(array($product_id));
192
193        // 規格1クラス名
194        $this->tpl_class_name1 = $objProduct->className1[$product_id];
195
196        // 規格2クラス名
197        $this->tpl_class_name2 = $objProduct->className2[$product_id];
198
199        // 規格1
200        $this->arrClassCat1 = $objProduct->classCats1[$product_id];
201
202        // 規格1が設定されている
203        $this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id];
204        // 規格2が設定されている
205        $this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id];
206
207        $this->tpl_stock_find = $objProduct->stock_find[$product_id];
208        $this->tpl_product_class_id = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_class_id'];
209        $this->tpl_product_type = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_type'];
210
211        // 在庫が無い場合は、OnLoadしない。(javascriptエラー防止)
212        if ($this->tpl_stock_find) {
213            // 規格選択セレクトボックスの作成
214            $this->js_lnOnload .= $this->lfMakeSelect();
215        }
216
217        $this->tpl_javascript .= 'eccube.classCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories[$product_id]) . ';';
218        $this->tpl_javascript .= 'function lnOnLoad()
219        {' . $this->js_lnOnload . '}';
220        $this->tpl_onload .= 'lnOnLoad();';
221
222        // モバイル用 規格選択セレクトボックスの作成
223        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
224            $this->lfMakeSelectMobile($this, $product_id, $this->objFormParam->getValue('classcategory_id1'));
225        }
226
227        // 商品IDをFORM内に保持する
228        $this->tpl_product_id = $product_id;
229
230        switch ($this->mode) {
231            case 'cart':
232                $this->doCart();
233                break;
234
235            case 'add_favorite':
236                $this->doAddFavorite($objCustomer);
237                break;
238
239            case 'add_favorite_sphone':
240                $this->doAddFavoriteSphone($objCustomer);
241                break;
242
243            case 'select':
244            case 'select2':
245            case 'selectItem':
246                /**
247                 * モバイルの数量指定・規格選択の際に、
248                 * $_SESSION['cart_referer_url'] を上書きさせないために、
249                 * 何もせずbreakする。
250                 */
251                break;
252
253            default:
254                $this->doDefault();
255                break;
256        }
257
258        // モバイル用 ポストバック処理
259        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
260            switch ($this->mode) {
261                case 'select':
262                    $this->doMobileSelect();
263                    break;
264
265                case 'select2':
266                    $this->doMobileSelect2();
267                    break;
268
269                case 'selectItem':
270                    $this->doMobileSelectItem();
271                    break;
272
273                case 'cart':
274                    $this->doMobileCart();
275                    break;
276
277                default:
278                    $this->doMobileDefault();
279                    break;
280            }
281        }
282
283        // 商品詳細を取得
284        $this->arrProduct = $objProduct->getDetail($product_id);
285
286        // サブタイトルを取得
287        $this->tpl_subtitle = $this->arrProduct['name'];
288
289        // 関連カテゴリを取得
290        $arrCategory_id = $objProduct->getCategoryIds($product_id);
291        $objCategory = new SC_Helper_Category_Ex();
292        $this->arrRelativeCat = array();
293        foreach ($arrCategory_id as $category_id) {
294            $this->arrRelativeCat[] = $objCategory->getTreeTrail($category_id, false);
295        }
296
297        // 商品ステータスを取得
298        $this->productStatus = $objProduct->getProductStatus($product_id);
299
300        // 画像ファイル指定がない場合の置換処理
301        $this->arrProduct['main_image']
302            = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']);
303
304        $this->subImageFlag = $this->lfSetFile($this->objUpFile, $this->arrProduct, $this->arrFile);
305        //レビュー情報の取得
306        $this->arrReview = $this->lfGetReviewData($product_id);
307
308        //関連商品情報表示
309        $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id);
310
311        // ログイン判定
312        if ($objCustomer->isLoginSuccess() === true) {
313            //お気に入りボタン表示
314            $this->tpl_login = true;
315            $this->is_favorite = SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($objCustomer->getValue('customer_id'), $product_id));
316        }
317    }
318
319    /**
320     * プロダクトIDの正当性チェック
321     *
322     * @param string $admin_mode
323     * @param int $product_id
324     * @return int|void
325     */
326    public function lfCheckProductId($admin_mode, $product_id)
327    {
328        // 管理機能からの確認の場合は、非公開の商品も表示する。
329        if (isset($admin_mode) && $admin_mode == 'on' && SC_Utils_Ex::sfIsSuccess(new SC_Session_Ex(), false)) {
330            $where = 'del_flg = 0';
331        } else {
332            $where = 'del_flg = 0 AND status = 1';
333        }
334
335        if (!SC_Utils_Ex::sfIsInt($product_id)
336            || SC_Utils_Ex::sfIsZeroFilling($product_id)
337            || !SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', (array) $product_id, $where)
338        ) {
339                SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
340        }
341
342        return $product_id;
343    }
344
345    /**
346     * ファイル情報の初期化
347     *
348     * @param SC_UploadFile $objUpFile
349     * @return SC_UploadFile
350     */
351    public function lfInitFile(SC_UploadFile $objUpFile)
352    {
353        $objUpFile->addFile('詳細-メイン画像', 'main_image', array('jpg'), IMAGE_SIZE);
354        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
355            $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE);
356        }
357
358        return $objUpFile;
359    }
360
361    /* 規格選択セレクトボックスの作成 */
362    public function lfMakeSelect()
363    {
364        return 'fnSetClassCategories('
365            . 'document.form1, '
366            . SC_Utils_Ex::jsonEncode($this->objFormParam->getValue('classcategory_id2'))
367            . '); ';
368    }
369
370    /* 規格選択セレクトボックスの作成(モバイル) */
371    public function lfMakeSelectMobile(&$objPage, $product_id, $request_classcategory_id1)
372    {
373        $classcat_find1 = false;
374        $classcat_find2 = false;
375
376        // 規格名一覧
377        $arrClassName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_class', 'class_id', 'name');
378        // 規格分類名一覧
379        $arrClassCatName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_classcategory', 'classcategory_id', 'name');
380        // 商品規格情報の取得
381        $arrProductsClass = $this->lfGetProductsClass($product_id);
382
383        // 規格1クラス名の取得
384        $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']];
385        // 規格2クラス名の取得
386        $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']];
387
388        // 全ての組み合わせ数
389        $count = count($arrProductsClass);
390
391        $classcat_id1 = '';
392        $classcat_id2 = '';
393
394        $arrSele1 = array();
395        $arrSele2 = array();
396
397        for ($i = 0; $i < $count; $i++) {
398            // 在庫のチェック
399            if ($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
400                continue;
401            }
402
403            // 規格1のセレクトボックス用
404            if ($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']) {
405                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
406                $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1];
407            }
408
409            // 規格2のセレクトボックス用
410            if ($arrProductsClass[$i]['classcategory_id1'] == $request_classcategory_id1 and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) {
411                $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
412                $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2];
413            }
414        }
415
416        // 規格1
417        $objPage->arrClassCat1 = $arrSele1;
418        $objPage->arrClassCat2 = $arrSele2;
419
420        // 規格1が設定されている
421        if (isset($arrProductsClass[0]['classcategory_id1']) && $arrProductsClass[0]['classcategory_id1'] != '0') {
422            $classcat_find1 = true;
423        }
424
425        // 規格2が設定されている
426        if (isset($arrProductsClass[0]['classcategory_id2']) && $arrProductsClass[0]['classcategory_id2'] != '0') {
427            $classcat_find2 = true;
428        }
429
430        $objPage->tpl_classcat_find1 = $classcat_find1;
431        $objPage->tpl_classcat_find2 = $classcat_find2;
432    }
433
434    /**
435     * パラメーター情報の初期化
436     *
437     * @param SC_FormParam $objFormParam
438     * @return array
439     */
440    public function lfInitParam(SC_FormParam &$objFormParam)
441    {
442        $objFormParam->addParam('規格1', 'classcategory_id1', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
443        $objFormParam->addParam('規格2', 'classcategory_id2', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
444        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
445        $objFormParam->addParam('管理者ログイン', 'admin', INT_LEN, 'a', array('ALNUM_CHECK','MAX_LENGTH_CHECK'));
446        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
447        $objFormParam->addParam('お気に入り商品ID', 'favorite_product_id', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
448        $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
449        // 値の取得
450        $objFormParam->setParam($_REQUEST);
451        // 入力値の変換
452        $objFormParam->convParam();
453        // 入力情報を渡す
454        return $objFormParam->getFormParamList();
455    }
456
457    /* 商品規格情報の取得 */
458    public function lfGetProductsClass($product_id)
459    {
460        $objProduct = new SC_Product_Ex();
461
462        return $objProduct->getProductsClassFullByProductId($product_id);
463    }
464
465    /* 登録済み関連商品の読み込み */
466    public function lfPreGetRecommendProducts($product_id)
467    {
468        $objProduct = new SC_Product_Ex();
469        $objQuery =& SC_Query_Ex::getSingletonInstance();
470
471        $objQuery->setOrder('rank DESC');
472        $arrRecommendData = $objQuery->select('recommend_product_id, comment', 'dtb_recommend_products as t1 left join dtb_products as t2 on t1.recommend_product_id = t2.product_id', 't1.product_id = ? and t2.del_flg = 0 and t2.status = 1', array($product_id));
473
474        $recommendProductIds = array();
475        foreach ($arrRecommendData as $recommend) {
476            $recommendProductIds[] = $recommend['recommend_product_id'];
477        }
478
479        $objQuery =& SC_Query_Ex::getSingletonInstance();
480        $arrProducts = $objProduct->getListByProductIds($objQuery, $recommendProductIds);
481
482        foreach ($arrRecommendData as $key => $arrRow) {
483            $arrRecommendData[$key] = array_merge($arrRow, $arrProducts[$arrRow['recommend_product_id']]);
484        }
485
486        return $arrRecommendData;
487    }
488
489    /* 入力内容のチェック */
490    public function lfCheckError($mode, SC_FormParam &$objFormParam, $tpl_classcat_find1 = null , $tpl_classcat_find2 = null)
491    {
492        switch ($mode) {
493        case 'add_favorite_sphone':
494        case 'add_favorite':
495            $objCustomer = new SC_Customer_Ex();
496            $objErr = new SC_CheckError_Ex();
497            $customer_id = $objCustomer->getValue('customer_id');
498            $favorite_product_id = $objCustomer->getValue('favorite_product_id');
499            if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) {
500                $objErr->arrErr['add_favorite'.$favorite_product_id] = '※ この商品は既にお気に入りに追加されています。<br />';
501            }
502            break;
503        default:
504            // 入力データを渡す。
505            $arrRet =  $objFormParam->getHashArray();
506            $objErr = new SC_CheckError_Ex($arrRet);
507            $objErr->arrErr = $objFormParam->checkError();
508
509            // 複数項目チェック
510            if ($tpl_classcat_find1) {
511                $objErr->doFunc(array('規格1', 'classcategory_id1'), array('EXIST_CHECK'));
512            }
513            if ($tpl_classcat_find2) {
514                $objErr->doFunc(array('規格2', 'classcategory_id2'), array('EXIST_CHECK'));
515            }
516            break;
517        }
518
519        return $objErr->arrErr;
520    }
521
522    /**
523     * 商品ごとのレビュー情報を取得する
524     *
525     * @param int $product_id
526     * @return array
527     */
528    public function lfGetReviewData($product_id)
529    {
530        $objQuery =& SC_Query_Ex::getSingletonInstance();
531        //商品ごとのレビュー情報を取得する
532        $col = 'create_date, reviewer_url, reviewer_name, recommend_level, title, comment';
533        $from = 'dtb_review';
534        $where = 'del_flg = 0 AND status = 1 AND product_id = ?';
535        $objQuery->setOrder('create_date DESC');
536        $objQuery->setLimit(REVIEW_REGIST_MAX);
537        $arrWhereVal = array($product_id);
538        $arrReview = $objQuery->select($col, $from, $where, $arrWhereVal);
539
540        return $arrReview;
541    }
542
543    /**
544     * ファイルの情報をセットする
545     *
546     * @param SC_UploadFile $objUpFile
547     * @param array $arrProduct
548     * @param array $arrFile
549     * @return bool
550     */
551    public function lfSetFile(SC_UploadFile $objUpFile, $arrProduct, &$arrFile)
552    {
553        // DBからのデータを引き継ぐ
554        $objUpFile->setDBFileList($arrProduct);
555        // ファイル表示用配列を渡す
556        $arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH, true);
557
558        // サブ画像の有無を判定
559        $subImageFlag = false;
560        for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) {
561            if ($arrFile['sub_image' . $i]['filepath'] != '') {
562                $subImageFlag = true;
563            }
564        }
565
566        return $subImageFlag;
567    }
568
569    /*
570     * お気に入り商品登録
571     * @return void
572     */
573    public function lfRegistFavoriteProduct($favorite_product_id, $customer_id)
574    {
575        // ログイン中のユーザが商品をお気に入りにいれる処理
576        if (!SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', $favorite_product_id, 'del_flg = 0 AND status = 1')) {
577            SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND);
578
579            return false;
580        } else {
581            $objQuery =& SC_Query_Ex::getSingletonInstance();
582            $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id));
583
584            if (!$exists) {
585                $sqlval['customer_id'] = $customer_id;
586                $sqlval['product_id'] = $favorite_product_id;
587                $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
588                $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
589
590                $objQuery->begin();
591                $objQuery->insert('dtb_customer_favorite_products', $sqlval);
592                $objQuery->commit();
593            }
594            // お気に入りに登録したことを示すフラグ
595            $this->just_added_favorite = true;
596
597            return true;
598        }
599    }
600
601    /**
602     * Add product(s) into the cart.
603     *
604     * @return void
605     */
606    public function doCart()
607    {
608        $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam,
609                                            $this->tpl_classcat_find1,
610                                            $this->tpl_classcat_find2);
611        if (count($this->arrErr) == 0) {
612            $objCartSess = new SC_CartSession_Ex();
613            $product_class_id = $this->objFormParam->getValue('product_class_id');
614
615            $objCartSess->addProduct($product_class_id, $this->objFormParam->getValue('quantity'));
616
617            // 開いているカテゴリーツリーを維持するためのパラメーター
618            $arrQueryString = array(
619                'product_id' => $this->objFormParam->getValue('product_id'),
620            );
621
622            SC_Response_Ex::sendRedirect(CART_URL, $arrQueryString);
623            SC_Response_Ex::actionExit();
624        }
625    }
626
627    /**
628     * Add product to authenticated user's favorites.
629     *
630     * @param  SC_Customer $objCustomer
631     * @return void
632     */
633    public function doAddFavorite(SC_Customer &$objCustomer)
634    {
635        // ログイン中のユーザが商品をお気に入りにいれる処理
636        if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) {
637            $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam);
638            if (count($this->arrErr) == 0) {
639                if (!$this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) {
640                    SC_Response_Ex::actionExit();
641                }
642                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
643                $objPlugin->doAction('LC_Page_Products_Detail_action_add_favorite', array($this));
644            }
645        }
646    }
647
648    /**
649     * Add product to authenticated user's favorites. (for Smart phone)
650     *
651     * @param  SC_Customer $objCustomer
652     * @return void
653     */
654    public function doAddFavoriteSphone(SC_Customer $objCustomer)
655    {
656        // ログイン中のユーザが商品をお気に入りにいれる処理(スマートフォン用)
657        if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) {
658            $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam);
659            if (count($this->arrErr) == 0) {
660                if ($this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) {
661                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
662                    $objPlugin->doAction('LC_Page_Products_Detail_action_add_favorite_sphone', array($this));
663                    print 'true';
664                    SC_Response_Ex::actionExit();
665                }
666            }
667            print 'error';
668            SC_Response_Ex::actionExit();
669        }
670    }
671
672    /**
673     *
674     *
675     * @return void
676     */
677    public function doDefault()
678    {
679        // カート「戻るボタン」用に保持
680        $netURL = new Net_URL();
681        $_SESSION['cart_referer_url'] = $netURL->getURL();
682    }
683
684    /**
685     *
686     * @return void
687     */
688    public function doMobileSelect()
689    {
690        // 規格1が設定されている場合
691        if ($this->tpl_classcat_find1) {
692            // templateの変更
693            $this->tpl_mainpage = 'products/select_find1.tpl';
694
695            return;
696        }
697
698        // 数量の入力を行う
699        $this->tpl_mainpage = 'products/select_item.tpl';
700    }
701
702    /**
703     *
704     * @return void
705     */
706    public function doMobileSelect2()
707    {
708        $this->arrErr = $this->lfCheckError($this->mode, $this->objFormParam, $this->tpl_classcat_find1, $this->tpl_classcat_find2);
709
710        // 規格1が設定されていて、エラーを検出した場合
711        if ($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) {
712            // templateの変更
713            $this->tpl_mainpage = 'products/select_find1.tpl';
714
715            return;
716        }
717
718        // 規格2が設定されている場合
719        if ($this->tpl_classcat_find2) {
720            $this->arrErr = array();
721
722            $this->tpl_mainpage = 'products/select_find2.tpl';
723
724            return;
725        }
726
727        $this->doMobileSelectItem();
728    }
729
730    /**
731     *
732     * @return void
733     */
734    public function doMobileSelectItem()
735    {
736        $objProduct = new SC_Product_Ex();
737
738        $this->arrErr = $this->lfCheckError($this->mode, $this->objFormParam, $this->tpl_classcat_find1, $this->tpl_classcat_find2);
739
740        // この段階では、商品規格ID・数量の入力チェックエラーを出させない。
741        // FIXME: エラーチェックの定義で mode で定義を分岐する方が良いように感じる
742        unset($this->arrErr['product_class_id']);
743        unset($this->arrErr['quantity']);
744
745        // 規格2が設定されていて、エラーを検出した場合
746        if ($this->tpl_classcat_find2 and !empty($this->arrErr)) {
747            // templateの変更
748            $this->tpl_mainpage = 'products/select_find2.tpl';
749
750            return;
751        }
752
753        $product_id = $this->objFormParam->getValue('product_id');
754
755        $value1 = $this->objFormParam->getValue('classcategory_id1');
756        if (strlen($value1) === 0) {
757            $value1 = '__unselected';
758        }
759
760        // 規格2が設定されている場合.
761        if (SC_Utils_Ex::isBlank($this->objFormParam->getValue('classcategory_id2')) == false) {
762            $value2 = '#' . $this->objFormParam->getValue('classcategory_id2');
763        } else {
764            $value2 = '#0';
765        }
766
767        $objProduct->setProductsClassByProductIds(array($product_id));
768        $this->tpl_product_class_id = $objProduct->classCategories[$product_id][$value1][$value2]['product_class_id'];
769
770        // 数量の入力を行う
771        $this->tpl_mainpage = 'products/select_item.tpl';
772    }
773
774    /**
775     *
776     * @return void
777     */
778    public function doMobileCart()
779    {
780        // この段階でエラーが出る場合は、数量の入力エラーのはず
781        if (count($this->arrErr)) {
782            // 数量の入力を行う
783            $this->tpl_mainpage = 'products/select_item.tpl';
784        }
785    }
786
787    /**
788     *
789     * @return void
790     */
791    public function doMobileDefault()
792    {
793        $this->tpl_mainpage = 'products/detail.tpl';
794    }
795}
Note: See TracBrowser for help on using the repository browser.