source: branches/version-2_5-dev/data/class/pages/mypage/LC_Page_Mypage_DeliveryAddr.php @ 20697

Revision 20697, 8.1 KB checked in by nanasess, 13 years ago (diff)

#1167 (非会員購入時, 複数お届け先の住所追加ができない)

  • 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-2010 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
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
26
27/**
28 * お届け先追加 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Mypage_DeliveryAddr extends LC_Page_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_title    = "お届け先の追加・変更";
47        $masterData         = new SC_DB_MasterData_Ex();
48        $this->arrPref      = $masterData->getMasterData('mtb_pref');
49        $this->httpCacheControl('nocache');
50        $this->validUrl = array(MYPAGE_DELIVADDR_URLPATH,
51                                DELIV_URLPATH,
52                                MULTIPLE_URLPATH);
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process() {
61        parent::process();
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のAction.
68     *
69     * @return void
70     */
71    function action() {
72        $objCustomer = new SC_Customer_Ex();
73        $ParentPage  = MYPAGE_DELIVADDR_URLPATH;
74
75        // GETでページを指定されている場合には指定ページに戻す
76        if (isset($_GET['page'])) {
77            $ParentPage = htmlspecialchars($_GET['page'], ENT_QUOTES);
78        } else if (isset($_POST['ParentPage'])) {
79            $ParentPage = htmlspecialchars($_POST['ParentPage'], ENT_QUOTES);
80        }
81        $this->ParentPage = $ParentPage;
82
83        /*
84         * ログイン判定 及び 退会判定
85         * 未ログインでも, 複数配送設定ページからのアクセスの場合は表示する
86         *
87         * TODO 購入遷移とMyPageで別クラスにすべき
88         */
89        if (!$objCustomer->isLoginSuccess(true) && $ParentPage != MULTIPLE_URLPATH){
90            $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
91        }
92
93        // $_GET['other_deliv_id'] のあるなしで追加か編集か判定しているらしい
94        if (!isset($_GET['other_deliv_id'])) $_GET['other_deliv_id'] = "";
95        $_SESSION['other_deliv_id'] = $_GET['other_deliv_id'];
96
97        // パラメータ管理クラス,パラメータ情報の初期化
98        $objFormParam   = new SC_FormParam_Ex();
99        SC_Helper_Customer_Ex::sfCustomerOtherDelivParam($objFormParam);
100        $objFormParam->setParam($_POST);
101        $this->arrForm  = $objFormParam->getHashArray();
102
103        switch ($this->getMode()) {
104            // 入力は必ずedit
105            case 'edit':
106                $this->arrErr = SC_Helper_Customer_Ex::sfCustomerOtherDelivErrorCheck($objFormParam);
107                // 入力エラーなし
108                if(empty($this->arrErr)) {
109
110                    // TODO ここでやるべきではない
111                    if (in_array($_POST['ParentPage'], $this->validUrl)) {
112                        $this->tpl_onload = "fnUpdateParent('". $this->getLocation($_POST['ParentPage']) ."'); window.close();";
113                    } else {
114                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
115                    }
116
117                    if ($objCustomer->isLoginSuccess(true)) {
118                        $this->lfRegistData($objFormParam, $objCustomer->getValue("customer_id"));
119                    } else {
120                        $this->lfRegistDataNonMember($objFormParam);
121                    }
122
123                    if(SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
124                        // モバイルの場合、元のページに遷移
125                        SC_Response_Ex::sendRedirect($this->getLocation($_POST['ParentPage']));
126                        exit;
127                    }
128                }
129                break;
130            case 'multiple':
131                // 複数配送先用
132                break;
133            default :
134
135                if ($_GET['other_deliv_id'] != ""){
136                    $arrOtherDeliv = $this->lfGetOtherDeliv($objCustomer->getValue("customer_id"), $_SESSION['other_deliv_id']);
137
138                    //不正アクセス判定
139                    if (!$objCustomer->isLoginSuccess(true)
140                        || count($arrOtherDeliv) == 0){
141                        SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
142                    }
143
144                    //別のお届け先情報取得
145                    $this->arrForm = $arrOtherDeliv[0];
146                }
147                break;
148        }
149
150        if (SC_Display_Ex::detectDevice() === DEVICE_TYPE_MOBILE) {
151            $this->tpl_mainpage = 'mypage/delivery_addr.tpl';
152        } else {
153            $this->setTemplate('mypage/delivery_addr.tpl');
154        }
155    }
156
157    /**
158     * デストラクタ.
159     *
160     * @return void
161     */
162    function destroy() {
163        parent::destroy();
164    }
165
166    /**
167     * ほかのお届け先を取得する
168     *
169     * @param mixed $customer_id
170     * @param mixed $other_deliv_id
171     * @access private
172     * @return array()
173     */
174    function lfGetOtherDeliv($customer_id, $other_deliv_id) {
175        $objQuery =& SC_Query_Ex::getSingletonInstance();
176        return $objQuery->select("*", "dtb_other_deliv", "customer_id = ? AND other_deliv_id = ?", array($customer_id, $other_deliv_id));
177
178         $arrOtherDeliv[0];
179    }
180
181    /* 登録実行 */
182    function lfRegistData($objFormParam, $customer_id) {
183        $objQuery   =& SC_Query_Ex::getSingletonInstance();
184
185        $arrRet     = $objFormParam->getHashArray();
186        $sqlval     = $objFormParam->getDbArray();
187
188        $sqlval['customer_id'] = $customer_id;
189
190        // 追加
191        if (strlen($arrRet['other_deliv_id'] == 0)) {
192            // 別のお届け先登録数の取得
193            $deliv_count = $objQuery->count("dtb_other_deliv", "customer_id = ?", array($customer_id));
194            // 別のお届け先最大登録数に達している場合、エラー
195            if ($deliv_count >= DELIV_ADDR_MAX) {
196                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
197            }
198
199            // 実行
200            $sqlval['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id');
201            $objQuery->insert("dtb_other_deliv", $sqlval);
202
203        // 変更
204        } else {
205            $deliv_count = $objQuery->count("dtb_other_deliv","customer_id = ? AND other_deliv_id = ?" ,array($customer_id, $arrRet['other_deliv_id']));
206            if ($deliv_count != 1) {
207                SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '一致する別のお届け先がありません。');
208            }
209
210            // 実行
211            $objQuery->update("dtb_other_deliv", $sqlval, "other_deliv_id = ?", array($arrRet['other_deliv_id']));
212        }
213    }
214
215    function lfRegistDataNonMember($objFormParam) {
216        $arrRegistColumn = $objFormParam->getDbArray();
217        foreach ($arrRegistColumn as $key => $val) {
218            $arrRegist['shipping_' . $key ] = $val;
219        }
220        if (count($_SESSION['shipping']) >= DELIV_ADDR_MAX) {
221            SC_Utils_Ex::sfDispSiteError(FREE_ERROR_MSG, "", false, '別のお届け先最大登録数に達しています。');
222        } else {
223            $_SESSION['shipping'][] = $arrRegist;
224        }
225    }
226}
227?>
Note: See TracBrowser for help on using the repository browser.