source: branches/version-2_13_0/data/class/pages/shopping/LC_Page_Shopping.php @ 23071

Revision 23071, 19.7 KB checked in by h_yoshimoto, 11 years ago (diff)

#2342 基本情報管理>SHOPマスターにてJSエラーで登録処理が動かなかったので一旦戻します

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