source: branches/version-2_13-dev/data/class/pages/shopping/LC_Page_Shopping.php @ 23647

Revision 23647, 20.3 KB checked in by Seasoft, 9 years ago (diff)

#2635 (無駄な処理を改善する for 2.13.4)

  • date() 第2引数は省略可
  • 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-2014 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
26/**
27 * ショッピングログインのページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Shopping extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_title = 'ログイン';
44        $masterData = new SC_DB_MasterData_Ex();
45        $this->arrPref = $masterData->getMasterData('mtb_pref');
46        $this->arrCountry = $masterData->getMasterData('mtb_country');
47        $this->arrSex = $masterData->getMasterData('mtb_sex');
48        $this->arrJob = $masterData->getMasterData('mtb_job');
49        $this->tpl_onload = 'eccube.toggleDeliveryForm();';
50
51        $objDate = new SC_Date_Ex(BIRTH_YEAR, date('Y'));
52        $this->arrYear = $objDate->getYear('', START_BIRTH_YEAR, '');
53        $this->arrMonth = $objDate->getMonth(true);
54        $this->arrDay = $objDate->getDay(true);
55
56        $this->httpCacheControl('nocache');
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    public function process()
65    {
66        parent::process();
67        $this->action();
68        $this->sendResponse();
69    }
70
71    /**
72     * Page のプロセス.
73     *
74     * @return void
75     */
76    public function action()
77    {
78        //決済処理中ステータスのロールバック
79        $objPurchase = new SC_Helper_Purchase_Ex();
80        $objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG);
81
82        $objSiteSess = new SC_SiteSession_Ex();
83        $objCartSess = new SC_CartSession_Ex();
84        $objCustomer = new SC_Customer_Ex();
85        $objCookie = new SC_Cookie_Ex();
86        $objFormParam = new SC_FormParam_Ex();
87
88        $nonmember_mainpage = 'shopping/nonmember_input.tpl';
89        $nonmember_title = 'お客様情報入力';
90
91        $this->tpl_uniqid = $objSiteSess->getUniqId();
92        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
93
94        $this->cartKey = $objCartSess->getKey();
95
96        // ログイン済みの場合は次画面に遷移
97        if ($objCustomer->isLoginSuccess(true)) {
98            SC_Response_Ex::sendRedirect(
99                    $this->getNextlocation($this->cartKey, $this->tpl_uniqid,
100                                           $objCustomer, $objPurchase,
101                                           $objSiteSess));
102            SC_Response_Ex::actionExit();
103        // 非会員かつ, ダウンロード商品の場合はエラー表示
104        } else {
105            if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) {
106                $msg = 'ダウンロード商品を含むお買い物は、会員登録が必要です。<br/>'
107                     . 'お手数ですが、会員登録をお願いします。';
108                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, $objSiteSess, false, $msg);
109                SC_Response_Ex::actionExit();
110            }
111        }
112
113        // 携帯端末IDが一致する会員が存在するかどうかをチェックする。
114        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
115            $this->tpl_valid_phone_id = $objCustomer->checkMobilePhoneId();
116        }
117
118        switch ($this->getMode()) {
119            // ログイン実行
120            case 'login':
121                $this->lfInitLoginFormParam($objFormParam);
122                $objFormParam->setParam($_POST);
123                $objFormParam->trimParam();
124                $objFormParam->convParam();
125                $objFormParam->toLower('login_email');
126                $this->arrErr = $objFormParam->checkError();
127
128                // ログイン判定
129                if (SC_Utils_Ex::isBlank($this->arrErr)
130                    && $objCustomer->doLogin($objFormParam->getValue('login_email'),
131                                             $objFormParam->getValue('login_pass'))) {
132                    // クッキー保存判定
133                    if ($objFormParam->getValue('login_memory') == '1' && strlen($objFormParam->getValue('login_email')) >= 1) {
134                        $objCookie->setCookie('login_email', $objFormParam->getValue('login_email'));
135                    } else {
136                        $objCookie->setCookie('login_email', '');
137                    }
138
139                    // モバイルサイトで携帯アドレスの登録が無い場合、携帯アドレス登録ページへ遷移
140                    if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
141                        if (!$objCustomer->hasValue('email_mobile')) {
142                            SC_Response_Ex::sendRedirectFromUrlPath('entry/email_mobile.php');
143                            SC_Response_Ex::actionExit();
144                        }
145                    // スマートフォンの場合はログイン成功を返す
146                    } elseif (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
147                        echo SC_Utils_Ex::jsonEncode(array('success' =>
148                                                     $this->getNextLocation($this->cartKey, $this->tpl_uniqid,
149                                                                            $objCustomer, $objPurchase,
150                                                                            $objSiteSess)));
151                        SC_Response_Ex::actionExit();
152                    }
153
154                    SC_Response_Ex::sendRedirect(
155                            $this->getNextLocation($this->cartKey, $this->tpl_uniqid,
156                                                   $objCustomer, $objPurchase,
157                                                   $objSiteSess));
158                    SC_Response_Ex::actionExit();
159                // ログインに失敗した場合
160                } else {
161                    // 仮登録の場合
162                    if (SC_Helper_Customer_Ex::checkTempCustomer($objFormParam->getValue('login_email'))) {
163                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
164                            echo $this->lfGetErrorMessage(TEMP_LOGIN_ERROR);
165                            SC_Response_Ex::actionExit();
166                        } else {
167                            SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
168                            SC_Response_Ex::actionExit();
169                        }
170                    } else {
171                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
172                            echo $this->lfGetErrorMessage(SITE_LOGIN_ERROR);
173                            SC_Response_Ex::actionExit();
174                        } else {
175                            SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
176                            SC_Response_Ex::actionExit();
177                        }
178                    }
179                }
180                break;
181            // お客様情報登録
182            case 'nonmember_confirm':
183                $this->tpl_mainpage = $nonmember_mainpage;
184                $this->tpl_title = $nonmember_title;
185                $this->lfInitParam($objFormParam);
186                $objFormParam->setParam($_POST);
187                $this->arrErr = $this->lfCheckError($objFormParam);
188
189                if (SC_Utils_Ex::isBlank($this->arrErr)) {
190                    $this->lfRegistData($this->tpl_uniqid, $objPurchase, $objCustomer, $objFormParam);
191
192                    $arrParams = $objFormParam->getHashArray();
193                    $shipping_id = $arrParams['deliv_check'] == '1' ? 1 : 0;
194                    $objPurchase->setShipmentItemTempForSole($objCartSess, $shipping_id);
195
196                    $objSiteSess->setRegistFlag();
197
198                    SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URLPATH);
199                    SC_Response_Ex::actionExit();
200                }
201                break;
202
203            // 前のページに戻る
204            case 'return':
205                SC_Response_Ex::sendRedirect(CART_URL);
206                SC_Response_Ex::actionExit();
207                break;
208
209            // 複数配送ページへ遷移
210            case 'multiple':
211                // 複数配送先指定が無効な場合はエラー
212                if (USE_MULTIPLE_SHIPPING === false) {
213                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
214                    SC_Response_Ex::actionExit();
215                }
216
217                $this->lfInitParam($objFormParam);
218                $objFormParam->setParam($_POST);
219                $this->arrErr = $this->lfCheckError($objFormParam);
220
221                if (SC_Utils_Ex::isBlank($this->arrErr)) {
222                    $this->lfRegistData($this->tpl_uniqid, $objPurchase, $objCustomer, $objFormParam, true);
223
224                    $objSiteSess->setRegistFlag();
225
226                    SC_Response_Ex::sendRedirect(MULTIPLE_URLPATH);
227                    SC_Response_Ex::actionExit();
228                }
229                $this->tpl_mainpage = $nonmember_mainpage;
230                $this->tpl_title = $nonmember_title;
231                break;
232
233            // お客様情報入力ページの表示
234            case 'nonmember':
235                $this->tpl_mainpage = $nonmember_mainpage;
236                $this->tpl_title = $nonmember_title;
237                $this->lfInitParam($objFormParam);
238                // ※breakなし
239
240            default:
241                // 前のページから戻ってきた場合は, お客様情報入力ページ
242                if (isset($_GET['from']) && $_GET['from'] == 'nonmember') {
243                    $this->tpl_mainpage = $nonmember_mainpage;
244                    $this->tpl_title = $nonmember_title;
245                    $this->lfInitParam($objFormParam);
246                } else {
247                    // 通常はログインページ
248                    $this->lfInitLoginFormParam($objFormParam);
249                }
250
251                $this->setFormParams($objFormParam, $objPurchase, $this->tpl_uniqid);
252                break;
253        }
254
255        // 入力値の取得
256        $this->arrForm = $objFormParam->getFormParamList();
257
258        // 記憶したメールアドレスを取得
259        $this->tpl_login_email = $objCookie->getCookie('login_email');
260        if (!SC_Utils_Ex::isBlank($this->tpl_login_email)) {
261            $this->tpl_login_memory = '1';
262        }
263    }
264
265    /**
266     * お客様情報入力時のパラメーター情報の初期化を行う.
267     *
268     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
269     * @return void
270     */
271    public function lfInitParam(&$objFormParam)
272    {
273        SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam, 'order_');
274        SC_Helper_Customer_Ex::sfCustomerRegisterParam($objFormParam, false, false, 'order_');
275
276        // 不要なパラメーターの削除
277        // XXX: 共通化したことをうまく使えば、以前あった購入同時会員登録も復活出来そうですが
278        $objFormParam->removeParam('order_password');
279        $objFormParam->removeParam('order_password02');
280        $objFormParam->removeParam('order_reminder');
281        $objFormParam->removeParam('order_reminder_answer');
282        $objFormParam->removeParam('order_mailmaga_flg');
283
284        $objFormParam->addParam('別のお届け先', 'deliv_check', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
285
286        SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam, 'shipping_');
287    }
288
289    /**
290     * ログイン時のパラメーター情報の初期化を行う.
291     *
292     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
293     * @return void
294     */
295    public function lfInitLoginFormParam(&$objFormParam)
296    {
297        $objFormParam->addParam('記憶する', 'login_memory', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
298        $objFormParam->addParam('メールアドレス', 'login_email', '', 'a', array('EXIST_CHECK', 'EMAIL_CHECK', 'SPTAB_CHECK', 'EMAIL_CHAR_CHECK'));
299        $objFormParam->addParam('パスワード', 'login_pass', PASSWORD_MAX_LEN, '', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
300
301        if ($this->tpl_valid_phone_id) {
302            // 携帯端末IDが登録されている場合、メールアドレス入力欄が省略される
303            $arrCheck4login_email = $objFormParam->getParamSetting('login_email', 'arrCheck');
304            $key = array_search('EXIST_CHECK', $arrCheck4login_email);
305            unset($arrCheck4login_email[$key]);
306            $objFormParam->overwriteParam('login_email', 'arrCheck', $arrCheck4login_email);
307        }
308    }
309
310    /**
311     * ログイン済みの場合の遷移先を取得する.
312     *
313     * 商品種別IDが, ダウンロード商品の場合は, 会員情報を受注一時情報に保存し,
314     * 支払方法選択画面のパスを返す.
315     * それ以外は, お届け先選択画面のパスを返す.
316     *
317     * @param  integer            $product_type_id 商品種別ID
318     * @param  string             $uniqid          受注一時テーブルのユニークID
319     * @param  SC_Customer        $objCustomer     SC_Customer インスタンス
320     * @param  SC_Helper_Purchase $objPurchase     SC_Helper_Purchase インスタンス
321     * @param  SC_SiteSession     $objSiteSess     SC_SiteSession インスタンス
322     * @return string             遷移先のパス
323     */
324    public function getNextLocation($product_type_id, $uniqid, &$objCustomer, &$objPurchase, &$objSiteSess)
325    {
326        switch ($product_type_id) {
327            case PRODUCT_TYPE_DOWNLOAD:
328                $objPurchase->unsetAllShippingTemp(true);
329                $objPurchase->saveOrderTemp($uniqid, array(), $objCustomer);
330                $objSiteSess->setRegistFlag();
331
332                return 'payment.php';
333
334            case PRODUCT_TYPE_NORMAL:
335            default:
336                return 'deliv.php';
337        }
338    }
339
340    /**
341     * データの一時登録を行う.
342     *
343     * 非会員向けの処理
344     * @param integer            $uniqid       受注一時テーブルのユニークID
345     * @param SC_Helper_Purchase $objPurchase  SC_Helper_Purchase インスタンス
346     * @param SC_Customer        $objCustomer  SC_Customer インスタンス
347     * @param SC_FormParam       $objFormParam SC_FormParam インスタンス
348     * @param boolean            $isMultiple   複数配送の場合 true
349     */
350    public function lfRegistData($uniqid, &$objPurchase, &$objCustomer, &$objFormParam, $isMultiple = false)
351    {
352        $arrParams = $objFormParam->getHashArray();
353
354        // 注文者をお届け先とする配列を取得
355        $arrShippingOwn = array();
356        $objPurchase->copyFromOrder($arrShippingOwn, $arrParams);
357
358        // 都度入力されたお届け先
359        $arrShipping = $objPurchase->extractShipping($arrParams);
360
361        if ($isMultiple) {
362            $objPurchase->unsetOneShippingTemp(0);
363            $objPurchase->unsetOneShippingTemp(1);
364            $objPurchase->saveShippingTemp($arrShippingOwn, 0);
365            if ($arrParams['deliv_check'] == '1') {
366                $objPurchase->saveShippingTemp($arrShipping, 1);
367            }
368        } else {
369            $objPurchase->unsetAllShippingTemp(true);
370            if ($arrParams['deliv_check'] == '1') {
371                $objPurchase->saveShippingTemp($arrShipping, 1);
372            } else {
373                $objPurchase->saveShippingTemp($arrShippingOwn, 0);
374            }
375        }
376
377        $arrValues = $objFormParam->getDbArray();
378
379        // 登録データの作成
380        $arrValues['order_birth'] = SC_Utils_Ex::sfGetTimestamp($arrParams['order_year'], $arrParams['order_month'], $arrParams['order_day']);
381        $arrValues['update_date'] = 'CURRENT_TIMESTAMP';
382        $arrValues['customer_id'] = '0';
383        $objPurchase->saveOrderTemp($uniqid, $arrValues, $objCustomer);
384    }
385
386    /**
387     * 入力内容のチェックを行う.
388     *
389     * 追加の必須チェック, 相関チェックを行うため, SC_CheckError を使用する.
390     *
391     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
392     * @return array        エラー情報の配
393     */
394    public function lfCheckError(&$objFormParam)
395    {
396        $arrParams = $objFormParam->getHashArray();
397
398        $objErr = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam, 'order_');
399
400        // 別のお届け先チェック
401        if (isset($arrParams['deliv_check']) && $arrParams['deliv_check'] == '1') {
402            $objErr2 = SC_Helper_Customer_Ex::sfCustomerCommonErrorCheck($objFormParam, 'shipping_');
403            $objErr->arrErr = array_merge((array) $objErr->arrErr, (array) $objErr2->arrErr);
404        } else {
405            // shipping系のエラーは無視
406            foreach ($objErr->arrErr as $key => $val) {
407                if (substr($key, 0, strlen('shipping_')) == 'shipping_') {
408                    unset($objErr->arrErr[$key]);
409                }
410            }
411        }
412
413        // 複数項目チェック
414        $objErr->doFunc(array('生年月日', 'order_year', 'order_month', 'order_day'), array('CHECK_BIRTHDAY'));
415        $objErr->doFunc(array('メールアドレス', 'メールアドレス(確認)', 'order_email', 'order_email02'), array('EQUAL_CHECK'));
416
417        return $objErr->arrErr;
418    }
419
420    /**
421     * 入力済みの購入情報をフォームに設定する.
422     *
423     * 受注一時テーブル, セッションの配送情報から入力済みの購入情報を取得し,
424     * フォームに設定する.
425     *
426     * @param  SC_FormParam       $objFormParam SC_FormParam インスタンス
427     * @param  SC_Helper_Purchase $objPurchase  SC_Helper_Purchase インスタンス
428     * @param  integer            $uniqid       購入一時情報のユニークID
429     * @return void
430     */
431    public function setFormParams(&$objFormParam, &$objPurchase, $uniqid)
432    {
433        $arrOrderTemp = $objPurchase->getOrderTemp($uniqid);
434        if (SC_Utils_Ex::isBlank($arrOrderTemp)) {
435            $arrOrderTemp = array(
436                'order_email' => '',
437                'order_birth' => '',
438            );
439        }
440        $arrShippingTemp = $objPurchase->getShippingTemp();
441
442        $objFormParam->setParam($arrOrderTemp);
443        /*
444         * count($arrShippingTemp) > 1 は複数配送であり,
445         * $arrShippingTemp[0] は注文者が格納されている
446         */
447        if (count($arrShippingTemp) > 1) {
448            $objFormParam->setParam($arrShippingTemp[1]);
449        } else {
450            if ($arrOrderTemp['deliv_check'] == 1) {
451                $objFormParam->setParam($arrShippingTemp[1]);
452            } else {
453                $objFormParam->setParam($arrShippingTemp[0]);
454            }
455        }
456        $objFormParam->setValue('order_email02', $arrOrderTemp['order_email']);
457        $objFormParam->setDBDate($arrOrderTemp['order_birth'], 'order_year', 'order_month', 'order_day');
458    }
459
460    /**
461     * エラーメッセージを JSON 形式で返す.
462     *
463     * TODO リファクタリング
464     * この関数は主にスマートフォンで使用します.
465     *
466     * @param integer エラーコード
467     * @return string JSON 形式のエラーメッセージ
468     * @see LC_PageError
469     */
470    public function lfGetErrorMessage($error)
471    {
472        switch ($error) {
473            case TEMP_LOGIN_ERROR:
474                $msg = "メールアドレスもしくはパスワードが正しくありません。\n本登録がお済みでない場合は、仮登録メールに記載されているURLより本登録を行ってください。";
475                break;
476            case SITE_LOGIN_ERROR:
477            default:
478                $msg = 'メールアドレスもしくはパスワードが正しくありません。';
479        }
480
481        return SC_Utils_Ex::jsonEncode(array('login_error' => $msg));
482    }
483}
Note: See TracBrowser for help on using the repository browser.