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

Revision 23315, 19.9 KB checked in by undertree, 10 years ago (diff)

#2411 非会員購入時に生年月日が登録されない 生年月日のprefixを調整

  • 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    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',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    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        // 非会員かつ, ダウンロード商品の場合はエラー表示
105        else {
106            if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) {
107                $msg = 'ダウンロード商品を含むお買い物は、会員登録が必要です。<br/>'
108                     . 'お手数ですが、会員登録をお願いします。';
109                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, $objSiteSess, false, $msg);
110                SC_Response_Ex::actionExit();
111            }
112        }
113
114        switch ($this->getMode()) {
115            // ログイン実行
116            case 'login':
117                $this->lfInitLoginFormParam($objFormParam);
118                $objFormParam->setParam($_POST);
119                $objFormParam->trimParam();
120                $objFormParam->convParam();
121                $objFormParam->toLower('login_email');
122                $this->arrErr = $objFormParam->checkError();
123
124                // ログイン判定
125                if (SC_Utils_Ex::isBlank($this->arrErr)
126                    && $objCustomer->doLogin($objFormParam->getValue('login_email'),
127                                             $objFormParam->getValue('login_pass'))) {
128                    // モバイルサイトで携帯アドレスの登録が無い場合、携帯アドレス登録ページへ遷移
129                    if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
130                        if (!$objCustomer->hasValue('email_mobile')) {
131                            SC_Response_Ex::sendRedirectFromUrlPath('entry/email_mobile.php');
132                            SC_Response_Ex::actionExit();
133                        }
134                    }
135                    // スマートフォンの場合はログイン成功を返す
136                    elseif (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
137                        echo SC_Utils_Ex::jsonEncode(array('success' =>
138                                                     $this->getNextLocation($this->cartKey, $this->tpl_uniqid,
139                                                                            $objCustomer, $objPurchase,
140                                                                            $objSiteSess)));
141                        SC_Response_Ex::actionExit();
142                    }
143
144                    // クッキー保存判定
145                    if ($objFormParam->getValue('login_memory') == '1' && $objFormParam->getValue('login_email') != '') {
146                        $objCookie->setCookie('login_email', $objFormParam->getValue('login_email'));
147                    } else {
148                        $objCookie->setCookie('login_email', '');
149                    }
150
151                    SC_Response_Ex::sendRedirect(
152                            $this->getNextLocation($this->cartKey, $this->tpl_uniqid,
153                                                   $objCustomer, $objPurchase,
154                                                   $objSiteSess));
155                    SC_Response_Ex::actionExit();
156                }
157                // ログインに失敗した場合
158                else {
159                    // 仮登録の場合
160                    if (SC_Helper_Customer_Ex::checkTempCustomer($objFormParam->getValue('login_email'))) {
161                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
162                            echo $this->lfGetErrorMessage(TEMP_LOGIN_ERROR);
163                            SC_Response_Ex::actionExit();
164                        } else {
165                            SC_Utils_Ex::sfDispSiteError(TEMP_LOGIN_ERROR);
166                            SC_Response_Ex::actionExit();
167                        }
168                    } else {
169                        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_SMARTPHONE) {
170                            echo $this->lfGetErrorMessage(SITE_LOGIN_ERROR);
171                            SC_Response_Ex::actionExit();
172                        } else {
173                            SC_Utils_Ex::sfDispSiteError(SITE_LOGIN_ERROR);
174                            SC_Response_Ex::actionExit();
175                        }
176                    }
177                }
178                break;
179            // お客様情報登録
180            case 'nonmember_confirm':
181                $this->tpl_mainpage = $nonmember_mainpage;
182                $this->tpl_title = $nonmember_title;
183                $this->lfInitParam($objFormParam);
184                $objFormParam->setParam($_POST);
185                $this->arrErr = $this->lfCheckError($objFormParam);
186
187                if (SC_Utils_Ex::isBlank($this->arrErr)) {
188                    $this->lfRegistData($this->tpl_uniqid, $objPurchase, $objCustomer, $objFormParam);
189
190                    $arrParams = $objFormParam->getHashArray();
191                    $shipping_id = $arrParams['deliv_check'] == '1' ? 1 : 0;
192                    $objPurchase->setShipmentItemTempForSole($objCartSess, $shipping_id);
193
194                    $objSiteSess->setRegistFlag();
195
196                    SC_Response_Ex::sendRedirect(SHOPPING_PAYMENT_URLPATH);
197                    SC_Response_Ex::actionExit();
198                }
199                break;
200
201            // 前のページに戻る
202            case 'return':
203                SC_Response_Ex::sendRedirect(CART_URL);
204                SC_Response_Ex::actionExit();
205                break;
206
207            // 複数配送ページへ遷移
208            case 'multiple':
209                // 複数配送先指定が無効な場合はエラー
210                if (USE_MULTIPLE_SHIPPING === false) {
211                    SC_Utils_Ex::sfDispSiteError(PAGE_ERROR, '', true);
212                    SC_Response_Ex::actionExit();
213                }
214
215                $this->lfInitParam($objFormParam);
216                $objFormParam->setParam($_POST);
217                $this->arrErr = $this->lfCheckError($objFormParam);
218
219                if (SC_Utils_Ex::isBlank($this->arrErr)) {
220                    $this->lfRegistData($this->tpl_uniqid, $objPurchase, $objCustomer, $objFormParam, true);
221
222                    $objSiteSess->setRegistFlag();
223
224                    SC_Response_Ex::sendRedirect(MULTIPLE_URLPATH);
225                    SC_Response_Ex::actionExit();
226                }
227                $this->tpl_mainpage = $nonmember_mainpage;
228                $this->tpl_title = $nonmember_title;
229                break;
230
231            // お客様情報入力ページの表示
232            case 'nonmember':
233                $this->tpl_mainpage = $nonmember_mainpage;
234                $this->tpl_title = $nonmember_title;
235                $this->lfInitParam($objFormParam);
236                // ※breakなし
237
238            default:
239                // 前のページから戻ってきた場合は, お客様情報入力ページ
240                if (isset($_GET['from']) && $_GET['from'] == 'nonmember') {
241                    $this->tpl_mainpage = $nonmember_mainpage;
242                    $this->tpl_title = $nonmember_title;
243                    $this->lfInitParam($objFormParam);
244                } else {
245                    // 通常はログインページ
246                    $this->lfInitLoginFormParam($objFormParam);
247                }
248
249                $this->setFormParams($objFormParam, $objPurchase, $this->tpl_uniqid);
250                break;
251        }
252
253        // 入力値の取得
254        $this->arrForm = $objFormParam->getFormParamList();
255
256        // 記憶したメールアドレスを取得
257        $this->tpl_login_email = $objCookie->getCookie('login_email');
258        if (!SC_Utils_Ex::isBlank($this->tpl_login_email)) {
259            $this->tpl_login_memory = '1';
260        }
261
262        // 携帯端末IDが一致する会員が存在するかどうかをチェックする。
263        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
264            $this->tpl_valid_phone_id = $objCustomer->checkMobilePhoneId();
265        }
266
267    }
268
269    /**
270     * お客様情報入力時のパラメーター情報の初期化を行う.
271     *
272     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
273     * @return void
274     */
275    public function lfInitParam(&$objFormParam)
276    {
277        SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam, 'order_');
278        SC_Helper_Customer_Ex::sfCustomerRegisterParam($objFormParam, false, false, 'order_');
279
280        // 不要なパラメーターの削除
281        // XXX: 共通化したことをうまく使えば、以前あった購入同時会員登録も復活出来そうですが
282        $objFormParam->removeParam('order_password');
283        $objFormParam->removeParam('order_password02');
284        $objFormParam->removeParam('order_reminder');
285        $objFormParam->removeParam('order_reminder_answer');
286        $objFormParam->removeParam('order_mailmaga_flg');
287
288        $objFormParam->addParam('別のお届け先', 'deliv_check', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
289
290        SC_Helper_Customer_Ex::sfCustomerCommonParam($objFormParam, 'shipping_');
291    }
292
293    /**
294     * ログイン時のパラメーター情報の初期化を行う.
295     *
296     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
297     * @return void
298     */
299    public function lfInitLoginFormParam(&$objFormParam)
300    {
301        $objFormParam->addParam('記憶する', 'login_memory', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
302        $objFormParam->addParam('メールアドレス', 'login_email', '' , 'a', array('EXIST_CHECK', 'EMAIL_CHECK', 'SPTAB_CHECK' ,'EMAIL_CHAR_CHECK'));
303        $objFormParam->addParam('パスワード', 'login_pass', PASSWORD_MAX_LEN, '', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
304    }
305
306    /**
307     * ログイン済みの場合の遷移先を取得する.
308     *
309     * 商品種別IDが, ダウンロード商品の場合は, 会員情報を受注一時情報に保存し,
310     * 支払方法選択画面のパスを返す.
311     * それ以外は, お届け先選択画面のパスを返す.
312     *
313     * @param  integer            $product_type_id 商品種別ID
314     * @param  string             $uniqid          受注一時テーブルのユニークID
315     * @param  SC_Customer        $objCustomer     SC_Customer インスタンス
316     * @param  SC_Helper_Purchase $objPurchase     SC_Helper_Purchase インスタンス
317     * @param  SC_SiteSession     $objSiteSess     SC_SiteSession インスタンス
318     * @return string             遷移先のパス
319     */
320    public function getNextLocation($product_type_id, $uniqid, &$objCustomer, &$objPurchase, &$objSiteSess)
321    {
322        switch ($product_type_id) {
323            case PRODUCT_TYPE_DOWNLOAD:
324                $objPurchase->unsetAllShippingTemp(true);
325                $objPurchase->saveOrderTemp($uniqid, array(), $objCustomer);
326                $objSiteSess->setRegistFlag();
327
328                return 'payment.php';
329
330            case PRODUCT_TYPE_NORMAL:
331            default:
332                return 'deliv.php';
333        }
334    }
335
336    /**
337     * データの一時登録を行う.
338     *
339     * 非会員向けの処理
340     * @param integer            $uniqid       受注一時テーブルのユニークID
341     * @param SC_Helper_Purchase $objPurchase  SC_Helper_Purchase インスタンス
342     * @param SC_Customer        $objCustomer  SC_Customer インスタンス
343     * @param SC_FormParam       $objFormParam SC_FormParam インスタンス
344     * @param boolean            $isMultiple   複数配送の場合 true
345     */
346    public function lfRegistData($uniqid, &$objPurchase, &$objCustomer, &$objFormParam, $isMultiple = false)
347    {
348        $arrParams = $objFormParam->getHashArray();
349
350        // 注文者をお届け先とする配列を取得
351        $arrShippingOwn = array();
352        $objPurchase->copyFromOrder($arrShippingOwn, $arrParams);
353
354        // 都度入力されたお届け先
355        $arrShipping = $objPurchase->extractShipping($arrParams);
356
357        if ($isMultiple) {
358            $objPurchase->unsetOneShippingTemp(0);
359            $objPurchase->unsetOneShippingTemp(1);
360            $objPurchase->saveShippingTemp($arrShippingOwn, 0);
361            if ($arrParams['deliv_check'] == '1') {
362                $objPurchase->saveShippingTemp($arrShipping, 1);
363            }
364        } else {
365            $objPurchase->unsetAllShippingTemp(true);
366            if ($arrParams['deliv_check'] == '1') {
367                $objPurchase->saveShippingTemp($arrShipping, 1);
368            } else {
369                $objPurchase->saveShippingTemp($arrShippingOwn, 0);
370            }
371        }
372
373        $arrValues = $objFormParam->getDbArray();
374
375        // 登録データの作成
376        $arrValues['order_birth'] = SC_Utils_Ex::sfGetTimestamp($arrParams['order_year'], $arrParams['order_month'], $arrParams['order_day']);
377        $arrValues['update_date'] = 'CURRENT_TIMESTAMP';
378        $arrValues['customer_id'] = '0';
379        $objPurchase->saveOrderTemp($uniqid, $arrValues, $objCustomer);
380    }
381
382    /**
383     * 入力内容のチェックを行う.
384     *
385     * 追加の必須チェック, 相関チェックを行うため, SC_CheckError を使用する.
386     *
387     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
388     * @return array        エラー情報の配
389     */
390    public function lfCheckError(&$objFormParam)
391    {
392        $arrParams = $objFormParam->getHashArray();
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('生年月日', 'order_year', 'order_month', 'order_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    public 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'], 'order_year', 'order_month', 'order_day');
454    }
455
456    /**
457     * エラーメッセージを JSON 形式で返す.
458     *
459     * TODO リファクタリング
460     * この関数は主にスマートフォンで使用します.
461     *
462     * @param integer エラーコード
463     * @return string JSON 形式のエラーメッセージ
464     * @see LC_PageError
465     */
466    public 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.