source: branches/version-2_13_2/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php @ 23408

Revision 23408, 7.0 KB checked in by m_uehara, 10 years ago (diff)

#2541 SC_Helper_Addressの処理の改善

  • 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_Mypage_DeliveryAddr extends LC_Page_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        $this->skip_load_page_layout = true;
43        parent::init();
44        $this->tpl_title    = 'お届け先の追加・変更';
45        $masterData         = new SC_DB_MasterData_Ex();
46        $this->arrPref      = $masterData->getMasterData('mtb_pref');
47        $this->arrCountry   = $masterData->getMasterData('mtb_country');
48        $this->httpCacheControl('nocache');
49        $this->validUrl = array(MYPAGE_DELIVADDR_URLPATH,
50                                DELIV_URLPATH,
51                                MULTIPLE_URLPATH);
52    }
53
54    /**
55     * Page のプロセス.
56     *
57     * @return void
58     */
59    public function process()
60    {
61        parent::process();
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のAction.
68     *
69     * @return void
70     */
71    public function action()
72    {
73        $objCustomer = new SC_Customer_Ex();
74        $objAddress  = new SC_Helper_Address_Ex();
75        $ParentPage  = MYPAGE_DELIVADDR_URLPATH;
76
77        // GETでページを指定されている場合には指定ページに戻す
78        if (isset($_GET['page'])) {
79            $ParentPage = htmlspecialchars($_GET['page'], ENT_QUOTES);
80        } elseif (isset($_POST['ParentPage'])) {
81            $ParentPage = htmlspecialchars($_POST['ParentPage'], ENT_QUOTES);
82        }
83
84        // 正しい遷移かをチェック
85        $arrParentPageList = array(DELIV_URLPATH, MYPAGE_DELIVADDR_URLPATH, MULTIPLE_URLPATH);
86        if(!SC_Utils_Ex::isBlank($ParentPage) && !in_array($ParentPage, $arrParentPageList)) {
87            // 遷移が正しくない場合、デフォルトであるマイページの配送先追加の画面を設定する
88            $ParentPage  = MYPAGE_DELIVADDR_URLPATH;
89        }
90
91        $this->ParentPage = $ParentPage;
92
93        /*
94         * ログイン判定 及び 退会判定
95         * 未ログインでも, 複数配送設定ページからのアクセスの場合は表示する
96         *
97         * TODO 購入遷移とMyPageで別クラスにすべき
98         */
99        if (!$objCustomer->isLoginSuccess(true) && $ParentPage != MULTIPLE_URLPATH) {
100            $this->tpl_onload = "eccube.changeParentUrl('". $ParentPage ."'); window.close();";
101        }
102
103        // other_deliv_id のあるなしで追加か編集か判定しているらしい
104        $_SESSION['other_deliv_id'] = $_REQUEST['other_deliv_id'];
105
106        // パラメーター管理クラス,パラメーター情報の初期化
107        $objFormParam   = new SC_FormParam_Ex();
108        $objAddress->setFormParam($objFormParam);
109        $objFormParam->setParam($_POST);
110
111        switch ($this->getMode()) {
112            // 入力は必ずedit
113            case 'edit':
114                $this->arrErr = $objAddress->errorCheck($objFormParam);
115                // 入力エラーなし
116                if (empty($this->arrErr)) {
117                    // TODO ここでやるべきではない
118                    if (in_array($_POST['ParentPage'], $this->validUrl)) {
119                        $this->tpl_onload = "eccube.changeParentUrl('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
120                    } else {
121                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
122                    }
123
124                    if ($objCustomer->isLoginSuccess(true)) {
125                        $this->lfRegistData($objAddress, $objFormParam, $objCustomer->getValue('customer_id'));
126                    } else {
127                        $this->lfRegistDataNonMember($objFormParam);
128                    }
129
130                    if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
131                        // モバイルの場合、元のページに遷移
132                        SC_Response_Ex::sendRedirect($this->getLocation($_POST['ParentPage']));
133                        SC_Response_Ex::actionExit();
134                    }
135                }
136                break;
137            case 'multiple':
138                // 複数配送先用
139                break;
140            default :
141
142                if ($_GET['other_deliv_id'] != '') {
143                    $arrOtherDeliv = $objAddress->getAddress($_SESSION['other_deliv_id'], $objCustomer->getValue('customer_id'));
144
145                    //不正アクセス判定
146                    if (!$objCustomer->isLoginSuccess(true) || !$arrOtherDeliv) {
147                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
148                    }
149
150                    //別のお届け先情報取得
151                    $objFormParam->setParam($arrOtherDeliv);
152                }
153                break;
154        }
155
156        $this->arrForm = $objFormParam->getFormParamList();
157        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
158            $this->tpl_mainpage = 'mypage/delivery_addr.tpl';
159        } else {
160            $this->setTemplate('mypage/delivery_addr.tpl');
161        }
162
163    }
164
165    /* 登録実行 */
166    public function lfRegistData($objAddress, $objFormParam, $customer_id)
167    {
168        $arrRet     = $objFormParam->getHashArray();
169        $sqlval     = $objFormParam->getDbArray();
170
171        $sqlval['other_deliv_id'] = $arrRet['other_deliv_id'];
172        $sqlval['customer_id'] = $customer_id;
173
174        if (!$objAddress->registAddress($sqlval)) {
175            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '別のお届け先を登録できませんでした。');
176            SC_Response_Ex::actionExit();
177        }
178    }
179
180    public function lfRegistDataNonMember($objFormParam)
181    {
182        $arrRegistColumn = $objFormParam->getDbArray();
183        foreach ($arrRegistColumn as $key => $val) {
184            $arrRegist['shipping_' . $key ] = $val;
185        }
186        if (count($_SESSION['shipping']) >= DELIV_ADDR_MAX) {
187            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, '', false, '別のお届け先最大登録数に達しています。');
188        } else {
189            $_SESSION['shipping'][] = $arrRegist;
190        }
191    }
192}
Note: See TracBrowser for help on using the repository browser.