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 |
---|
25 | require_once(CLASS_REALDIR . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * 支払い方法選択 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Shopping_Payment extends LC_Page { |
---|
35 | |
---|
36 | // {{{ properties |
---|
37 | |
---|
38 | /** フォームパラメータの配列 */ |
---|
39 | var $objFormParam; |
---|
40 | |
---|
41 | /** 顧客情報のインスタンス */ |
---|
42 | var $objCustomer; |
---|
43 | |
---|
44 | // }}} |
---|
45 | // {{{ functions |
---|
46 | |
---|
47 | /** |
---|
48 | * Page を初期化する. |
---|
49 | * |
---|
50 | * @return void |
---|
51 | */ |
---|
52 | function init() { |
---|
53 | parent::init(); |
---|
54 | $this->tpl_onload = "fnCheckInputPoint(); fnSetDelivTime('payment','payment_id','deliv_time_id');"; |
---|
55 | $this->tpl_title = "お支払方法・お届け時間等の指定"; |
---|
56 | $masterData = new SC_DB_MasterData(); |
---|
57 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Page のプロセス. |
---|
62 | * |
---|
63 | * @return void |
---|
64 | */ |
---|
65 | function process() { |
---|
66 | parent::process(); |
---|
67 | $this->action(); |
---|
68 | $this->sendResponse(); |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * Page のアクション. |
---|
73 | * |
---|
74 | * @return void |
---|
75 | */ |
---|
76 | function action() { |
---|
77 | $objSiteSess = new SC_SiteSession(); |
---|
78 | $objCartSess = new SC_CartSession(); |
---|
79 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
80 | $this->objCustomer = new SC_Customer(); |
---|
81 | |
---|
82 | $this->shipping =& $objPurchase->getShippingTemp(); |
---|
83 | $this->isMultiple = $objPurchase->isMultiple(); |
---|
84 | |
---|
85 | // パラメータ管理クラス |
---|
86 | $this->objFormParam = new SC_FormParam(); |
---|
87 | // パラメータ情報の初期化 |
---|
88 | $this->lfInitParam(); |
---|
89 | // POST値の取得 |
---|
90 | $this->objFormParam->setParam($_POST); |
---|
91 | |
---|
92 | $uniqid = $objSiteSess->getUniqId(); |
---|
93 | $objPurchase->verifyChangeCart($uniqid, $objCartSess); |
---|
94 | |
---|
95 | // ユニークIDを引き継ぐ |
---|
96 | $this->tpl_uniqid = $uniqid; |
---|
97 | |
---|
98 | $this->cartKey = $objCartSess->getKey(); |
---|
99 | |
---|
100 | // 配送時間を取得 |
---|
101 | $this->arrDelivTime = $objPurchase->getDelivTime($this->cartKey); |
---|
102 | |
---|
103 | // 会員ログインチェック |
---|
104 | if($this->objCustomer->isLoginSuccess()) { |
---|
105 | $this->tpl_login = '1'; |
---|
106 | $this->tpl_user_point = $this->objCustomer->getValue('point'); |
---|
107 | //戻り先URL |
---|
108 | if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) { |
---|
109 | // ダウンロード商品のみの場合はカート画面へ戻る |
---|
110 | $this->tpl_back_url = CART_URL_PATH; |
---|
111 | } else { |
---|
112 | $this->tpl_back_url = DELIV_URL_PATH; |
---|
113 | } |
---|
114 | } else { |
---|
115 | $this->tpl_back_url = SHOPPING_URL . "?from=nonmember"; |
---|
116 | } |
---|
117 | |
---|
118 | // 一時受注テーブルの読込 |
---|
119 | $arrOrderTemp = $objPurchase->getOrderTemp($uniqid); |
---|
120 | //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す) |
---|
121 | if (!$arrOrderTemp) { |
---|
122 | SC_Response_Ex::sendRedirect(CART_URL_PATH); |
---|
123 | exit; |
---|
124 | } |
---|
125 | |
---|
126 | // カート内商品の集計処理を行う |
---|
127 | $this->cartItems = $objCartSess->getCartList($this->cartKey); |
---|
128 | $this->tpl_message = $objCartSess->checkProducts($this->cartKey); |
---|
129 | |
---|
130 | if (strlen($this->tpl_message) >= 1) { |
---|
131 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true); |
---|
132 | } |
---|
133 | // FIXME 使用ポイント, 手数料の扱い |
---|
134 | $this->arrData = $objCartSess->calculate($this->cartKey, $objCustomer, 0, $objPurchase->getShippingPref()); |
---|
135 | |
---|
136 | // 購入金額の取得 |
---|
137 | $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey); |
---|
138 | |
---|
139 | // 支払い方法の取得 |
---|
140 | $this->arrPayment = $objPurchase->getPayment($total_inctax, $objCartSess->getAllProductClassID($this->cartKey)); |
---|
141 | |
---|
142 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
143 | |
---|
144 | switch($_POST['mode']) { |
---|
145 | case 'confirm': |
---|
146 | // 入力値の変換 |
---|
147 | $this->objFormParam->convParam(); |
---|
148 | $this->arrErr = $this->lfCheckError($this->arrData, $this->arrPayment); |
---|
149 | // 入力エラーなし |
---|
150 | if(count($this->arrErr) == 0) { |
---|
151 | |
---|
152 | foreach (array_keys($_SESSION['shipping']) as $key) { |
---|
153 | $timeId = $this->objFormParam->getValue('deliv_time_id' . $key); |
---|
154 | /* TODO |
---|
155 | * SC_Purchase::getShippingTemp() で取得して, |
---|
156 | * リファレンスで代入すると, セッションに添字を追加できない? |
---|
157 | */ |
---|
158 | $_SESSION['shipping'][$key]['time_id'] = $timeId; |
---|
159 | $_SESSION['shipping'][$key]['shipping_time'] = $this->arrDelivTime[$timeId]; |
---|
160 | $_SESSION['shipping'][$key]['shipping_date'] = $this->objFormParam->getValue('deliv_date' . $key); |
---|
161 | } |
---|
162 | $this->lfRegistData($uniqid, $objPurchase); |
---|
163 | |
---|
164 | // 正常に登録されたことを記録しておく |
---|
165 | $objSiteSess->setRegistFlag(); |
---|
166 | // 確認ページへ移動 |
---|
167 | SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URL_PATH); |
---|
168 | exit; |
---|
169 | }else{ |
---|
170 | // ユーザユニークIDの取得 |
---|
171 | $uniqid = $objSiteSess->getUniqId(); |
---|
172 | // 受注一時テーブルからの情報を格納 |
---|
173 | $this->objFormParam->setParam($objPurchase->getOrderTemp($uniqid)); |
---|
174 | } |
---|
175 | break; |
---|
176 | // 前のページに戻る |
---|
177 | case 'return': |
---|
178 | // 非会員の場合 |
---|
179 | // 正常な推移であることを記録しておく |
---|
180 | $objSiteSess->setRegistFlag(); |
---|
181 | SC_Response_Ex::sendRedirect(SHOPPING_URL); |
---|
182 | exit; |
---|
183 | break; |
---|
184 | |
---|
185 | default: |
---|
186 | // 受注一時テーブルからの情報を格納 |
---|
187 | $this->objFormParam->setParam($arrOrderTemp); |
---|
188 | break; |
---|
189 | } |
---|
190 | |
---|
191 | // 支払い方法の画像があるなしを取得($img_show true:ある false:なし) |
---|
192 | $this->img_show = $this->lfGetImgShow($this->arrPayment); |
---|
193 | // お届け日一覧の取得 |
---|
194 | $this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $this->cartKey); |
---|
195 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
196 | } |
---|
197 | |
---|
198 | /** |
---|
199 | * デストラクタ. |
---|
200 | * |
---|
201 | * @return void |
---|
202 | */ |
---|
203 | function destroy() { |
---|
204 | parent::destroy(); |
---|
205 | } |
---|
206 | |
---|
207 | /* パラメータ情報の初期化 */ |
---|
208 | function lfInitParam() { |
---|
209 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
210 | $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START")); |
---|
211 | $this->objFormParam->addParam("その他お問い合わせ", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
212 | $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2'); |
---|
213 | |
---|
214 | for ($i = 0; $i < count($this->shipping); $i++) { |
---|
215 | $this->objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
216 | $this->objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | |
---|
221 | /* 入力内容のチェック */ |
---|
222 | function lfCheckError($arrData, $arrPayment) { |
---|
223 | // 入力データを渡す。 |
---|
224 | $arrRet = $this->objFormParam->getHashArray(); |
---|
225 | $objErr = new SC_CheckError($arrRet); |
---|
226 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
227 | |
---|
228 | if (USE_POINT === false) { |
---|
229 | $_POST['point_check'] = ""; |
---|
230 | $_POST['use_point'] = "0"; |
---|
231 | } |
---|
232 | |
---|
233 | if (!isset($_POST['point_check'])) $_POST['point_check'] = ""; |
---|
234 | |
---|
235 | if($_POST['point_check'] == '1') { |
---|
236 | $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK")); |
---|
237 | $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK")); |
---|
238 | $max_point = $this->objCustomer->getValue('point'); |
---|
239 | if($max_point == "") { |
---|
240 | $max_point = 0; |
---|
241 | } |
---|
242 | // FIXME mobile 互換のため br は閉じない... |
---|
243 | if($arrRet['use_point'] > $max_point) { |
---|
244 | $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>"; |
---|
245 | } |
---|
246 | if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) { |
---|
247 | $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>"; |
---|
248 | } |
---|
249 | } |
---|
250 | |
---|
251 | $objCartSess = new SC_CartSession(); |
---|
252 | // 購入金額の取得得 |
---|
253 | $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey); |
---|
254 | $pay_flag = true; |
---|
255 | foreach ($arrPayment as $key => $payment) { |
---|
256 | if ($payment['payment_id'] == $arrRet['payment_id']) { |
---|
257 | $pay_flag = false; |
---|
258 | break; |
---|
259 | } |
---|
260 | } |
---|
261 | if ($pay_flag && $arrRet['payment_id'] != "") { |
---|
262 | SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); |
---|
263 | } |
---|
264 | |
---|
265 | return $objErr->arrErr; |
---|
266 | } |
---|
267 | |
---|
268 | /* 支払い方法文字列の取得 */ |
---|
269 | function lfGetPaymentInfo($payment_id) { |
---|
270 | $objQuery = new SC_Query(); |
---|
271 | $where = "payment_id = ?"; |
---|
272 | $arrRet = $objQuery->getRow("charge, payment_method", "dtb_payment", $where, array($payment_id)); |
---|
273 | return (array($arrRet['charge'], $arrRet['payment_method'])); |
---|
274 | } |
---|
275 | |
---|
276 | /* DBへデータの登録 */ |
---|
277 | function lfRegistData($uniqid, &$objPurchase) { |
---|
278 | |
---|
279 | $sqlval = $this->objFormParam->getDbArray(); |
---|
280 | // 登録データの作成 |
---|
281 | $sqlval['order_temp_id'] = $uniqid; |
---|
282 | $sqlval['update_date'] = 'Now()'; |
---|
283 | |
---|
284 | if (strlen($sqlval['payment_id']) >= 1) { |
---|
285 | list($sqlval['charge'], $sqlval['payment_method']) = $this->lfGetPaymentInfo($sqlval['payment_id']); |
---|
286 | } |
---|
287 | |
---|
288 | // 使用ポイントの設定 |
---|
289 | if($sqlval['point_check'] != '1') { |
---|
290 | $sqlval['use_point'] = 0; |
---|
291 | } |
---|
292 | |
---|
293 | $objPurchase->saveOrderTemp($uniqid, $sqlval); |
---|
294 | } |
---|
295 | |
---|
296 | //一時受注テーブルからの情報を格納する |
---|
297 | function lfSetOrderTempData($uniqid, &$objPurchase) { |
---|
298 | $arrOrderTemp = $objPurchase->getOrderTemp($uniqid); |
---|
299 | $this->objFormParam->setParam($arrOrderTemp); |
---|
300 | return $this->objFormParam; |
---|
301 | } |
---|
302 | |
---|
303 | /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */ |
---|
304 | function lfGetImgShow($arrPayment) { |
---|
305 | $img_show = false; |
---|
306 | foreach ($arrPayment as $payment) { |
---|
307 | if (strlen($payment["payment_image"]) > 0 ){ |
---|
308 | $img_show = true; |
---|
309 | break; |
---|
310 | } |
---|
311 | } |
---|
312 | return $img_show; |
---|
313 | } |
---|
314 | } |
---|
315 | ?> |
---|