source: branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_DeliveryInput.php @ 22566

Revision 22566, 8.4 KB checked in by pineray, 11 years ago (diff)

#2136 #2134 get した値をそのまま save できるように調整.

  • 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
24// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
26
27/**
28 * 配送方法設定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Basis_DeliveryInput extends LC_Page_Admin_Ex {
35    // }}}
36    // {{{ functions
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    function init() {
44        parent::init();
45        $this->tpl_mainpage = 'basis/delivery_input.tpl';
46        $this->tpl_subno = 'delivery';
47        $this->tpl_mainno = 'basis';
48        $masterData = new SC_DB_MasterData_Ex();
49        $this->arrPref = $masterData->getMasterData('mtb_pref');
50        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
51        $this->arrPayments = SC_Helper_Payment_Ex::getIDValueList();
52        $this->tpl_maintitle = '基本情報管理';
53        $this->tpl_subtitle = '配送方法設定';
54        $this->mode = $this->getMode();
55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
70     * @return void
71     */
72    function action() {
73        $objFormParam = new SC_FormParam_Ex();
74        $this->lfInitParam($this->mode, $objFormParam);
75        $objFormParam->setParam($_POST);
76
77        // 入力値の変換
78        $objFormParam->convParam();
79        $this->arrErr = $this->lfCheckError($objFormParam);
80
81        switch ($this->mode) {
82            case 'edit':
83                if (count($this->arrErr) == 0) {
84                    $objFormParam->setValue('deliv_id', $this->lfRegistData($objFormParam->getHashArray(), $_SESSION['member_id']));
85                    $this->tpl_onload = "window.alert('配送方法設定が完了しました。');";
86                }
87                break;
88            case 'pre_edit':
89                if (count($this->arrErr) > 0) {
90                    trigger_error('', E_USER_ERROR);
91                }
92                $this->lfGetDelivData($objFormParam);
93                break;
94            default:
95                break;
96        }
97
98        $this->arrForm = $objFormParam->getFormParamList();
99
100    }
101
102    /**
103     * デストラクタ.
104     *
105     * @return void
106     */
107    function destroy() {
108        parent::destroy();
109    }
110
111    /* パラメーター情報の初期化 */
112    function lfInitParam($mode, &$objFormParam) {
113        $objFormParam = new SC_FormParam_Ex();
114
115        switch ($mode) {
116            case 'edit':
117                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
118                $objFormParam->addParam('配送業者名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
119                $objFormParam->addParam('名称', 'service_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
120                $objFormParam->addParam('説明', 'remark', LLTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
121                $objFormParam->addParam('伝票No.確認URL', 'confirm_url', URL_LEN, 'n', array('URL_CHECK', 'MAX_LENGTH_CHECK'), 'http://');
122                $objFormParam->addParam('取扱商品種別', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
123                $objFormParam->addParam('取扱支払方法', 'payment_ids', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
124
125                for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
126                    $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
127                }
128
129                if (INPUT_DELIV_FEE) {
130                    for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
131                        $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
132                    }
133                }
134                break;
135
136            case 'pre_edit':
137                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
138                break;
139
140            default:
141                break;
142        }
143    }
144
145    /**
146     * 配送情報を登録する
147     *
148     * @return $deliv_id
149     */
150    function lfRegistData($arrRet, $member_id) {
151        $objDelivery = new SC_Helper_Delivery_Ex();
152
153        // 入力データを渡す。
154        $sqlval['deliv_id'] = $arrRet['deliv_id'];
155        $sqlval['name'] = $arrRet['name'];
156        $sqlval['service_name'] = $arrRet['service_name'];
157        $sqlval['remark'] = $arrRet['remark'];
158        $sqlval['confirm_url'] = $arrRet['confirm_url'];
159        $sqlval['product_type_id'] = $arrRet['product_type_id'];
160        $sqlval['creator_id'] = $member_id;
161
162        // お届け時間
163        $sqlval['deliv_time'] = array();
164        for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
165            $keyname = "deliv_time$cnt";
166            if ($arrRet[$keyname] != '') {
167                $sqlval['deliv_time'][$cnt] = $arrRet[$keyname];
168            }
169        }
170
171        // 配送料
172        if (INPUT_DELIV_FEE) {
173            $sqlval['deliv_fee'] = array();
174            // 配送料金の設定
175            for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
176                $keyname = "fee$cnt";
177                if ($arrRet[$keyname] != '') {
178                    $fee = array();
179                    $fee['fee_id'] = $cnt;
180                    $fee['fee'] = $arrRet[$keyname];
181                    $fee['pref'] = $cnt;
182                    $sqlval['deliv_fee'][$cnt] = $fee;
183                }
184            }
185        }
186
187        // 支払い方法
188        $sqlval['payment_ids'] = array();
189        foreach ($arrRet['payment_ids'] as $payment_id) {
190            $sqlval['payment_ids'][] = $payment_id;
191        }
192
193        $deliv_id = $objDelivery->save($sqlval);
194
195        return $deliv_id;
196    }
197
198    /* 配送業者情報の取得 */
199    function lfGetDelivData(&$objFormParam) {
200        $objDelivery = new SC_Helper_Delivery_Ex();
201
202        $deliv_id = $objFormParam->getValue('deliv_id');
203
204        // パラメーター情報の初期化
205        $this->lfInitParam('edit', $objFormParam);
206
207        $arrDeliv = $objDelivery->get($deliv_id);
208
209        // お届け時間
210        $deliv_times = array();
211        foreach ($arrDeliv['deliv_time'] as $value) {
212            $deliv_times[]['deliv_time'] = $value;
213        }
214        $objFormParam->setParamList($deliv_times, 'deliv_time');
215        unset($arrDeliv['deliv_time']);
216        // 配送料金
217        $deliv_fee = array();
218        foreach ($arrDeliv['deliv_fee'] as $value) {
219            $deliv_fee[]['fee'] = $value['fee'];
220        }
221        $objFormParam->setParamList($deliv_fee, 'fee');
222        unset($arrDeliv['deliv_fee']);
223        // 支払方法
224        $objFormParam->setValue('payment_ids', $arrDeliv['payment_ids']);
225        unset($arrDeliv['payment_ids']);
226        // 配送業者
227        $objFormParam->setParam($arrDeliv);
228    }
229
230    /* 入力内容のチェック */
231    function lfCheckError(&$objFormParam) {
232        // 入力データを渡す。
233        $arrRet =  $objFormParam->getHashArray();
234        $objErr = new SC_CheckError_Ex($arrRet);
235        $objErr->arrErr = $objFormParam->checkError();
236
237        if (!isset($objErr->arrErr['name'])) {
238            // 既存チェック
239            $objDelivery = new SC_Helper_Delivery_Ex();
240            if ($objDelivery->checkExist($arrRet)) {
241                $objErr->arrErr['service_name'] = '※ 同じ名称の組み合わせは登録できません。<br>';
242            }
243        }
244
245        return $objErr->arrErr;
246    }
247}
Note: See TracBrowser for help on using the repository browser.