source: branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 19923

Revision 19923, 11.4 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

  • お届け日/お届け時間が反映されるよう修正
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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_REALDIR . "pages/LC_Page.php");
26
27/**
28 * 支払い方法選択 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class 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);
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                    $_SESSION['shipping'][$key]['time_id'] = $timeId;
155                    $_SESSION['shipping'][$key]['shipping_time'] = $this->arrDelivTime[$timeId];
156                    // XXX 文字列を代入しておいてもDBで自動変換可能?
157                    $_SESSION['shipping'][$key]['shipping_date'] = $this->objFormParam->getValue('deliv_date' . $key);
158                }
159                $this->lfRegistData($uniqid, $objPurchase);
160
161                // 正常に登録されたことを記録しておく
162                $objSiteSess->setRegistFlag();
163                // 確認ページへ移動
164                SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URL_PATH);
165                exit;
166            }else{
167                // ユーザユニークIDの取得
168                $uniqid = $objSiteSess->getUniqId();
169                // 受注一時テーブルからの情報を格納
170                $this->objFormParam->setParam($objPurchase->getOrderTemp($uniqid));
171            }
172            break;
173        // 前のページに戻る
174        case 'return':
175            // 非会員の場合
176            // 正常な推移であることを記録しておく
177            $objSiteSess->setRegistFlag();
178            SC_Response_Ex::sendRedirect(SHOPPING_URL);
179            exit;
180            break;
181
182        default:
183            // 受注一時テーブルからの情報を格納
184            $this->objFormParam->setParam($arrOrderTemp);
185            break;
186        }
187
188        // 支払い方法の画像があるなしを取得($img_show true:ある false:なし)
189        $this->img_show = $this->lfGetImgShow($this->arrPayment);
190        // お届け日一覧の取得
191        $this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $this->cartKey);
192        $this->arrForm = $this->objFormParam->getFormParamList();
193    }
194
195    /**
196     * デストラクタ.
197     *
198     * @return void
199     */
200    function destroy() {
201        parent::destroy();
202    }
203
204    /* パラメータ情報の初期化 */
205    function lfInitParam() {
206        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
207        $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
208        $this->objFormParam->addParam("その他お問い合わせ", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
209        $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
210
211        for ($i = 0; $i < count($this->shipping); $i++) {
212            $this->objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
213            $this->objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
214        }
215    }
216
217 
218    /* 入力内容のチェック */
219    function lfCheckError($arrData, $arrPayment) {
220        // 入力データを渡す。
221        $arrRet =  $this->objFormParam->getHashArray();
222        $objErr = new SC_CheckError($arrRet);
223        $objErr->arrErr = $this->objFormParam->checkError();
224
225        if (USE_POINT === false) {
226            $_POST['point_check'] = "";
227            $_POST['use_point'] = "0";
228        }
229
230        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
231
232        if($_POST['point_check'] == '1') {
233            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
234            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
235            $max_point = $this->objCustomer->getValue('point');
236            if($max_point == "") {
237                $max_point = 0;
238            }
239            // FIXME mobile 互換のため br は閉じない...
240            if($arrRet['use_point'] > $max_point) {
241                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
242            }
243            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
244                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
245            }
246        }
247
248        $objCartSess = new SC_CartSession();
249        // 購入金額の取得得
250        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
251        $pay_flag = true;
252        foreach ($arrPayment as $key => $payment) {
253            if ($payment['payment_id'] == $arrRet['payment_id']) {
254                $pay_flag = false;
255                break;
256            }
257        }
258        if ($pay_flag && $arrRet['payment_id'] != "") {
259            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
260        }
261
262        return $objErr->arrErr;
263    }
264
265    /* 支払い方法文字列の取得 */
266    function lfGetPaymentInfo($payment_id) {
267        $objQuery = new SC_Query();
268        $where = "payment_id = ?";
269        $arrRet = $objQuery->getRow("charge, payment_method", "dtb_payment", $where, array($payment_id));
270        return (array($arrRet['charge'], $arrRet['payment_method']));
271    }
272
273    /* DBへデータの登録 */
274    function lfRegistData($uniqid, &$objPurchase) {
275
276        $sqlval = $this->objFormParam->getDbArray();
277        // 登録データの作成
278        $sqlval['order_temp_id'] = $uniqid;
279        $sqlval['update_date'] = 'Now()';
280
281        if (strlen($sqlval['payment_id']) >= 1) {
282            list($sqlval['charge'], $sqlval['payment_method']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
283        }
284
285        // 使用ポイントの設定
286        if($sqlval['point_check'] != '1') {
287            $sqlval['use_point'] = 0;
288        }
289
290        $objPurchase->saveOrderTemp($uniqid, $sqlval);
291    }
292
293    //一時受注テーブルからの情報を格納する
294    function lfSetOrderTempData($uniqid, &$objPurchase) {
295        $arrOrderTemp = $objPurchase->getOrderTemp($uniqid);
296        $this->objFormParam->setParam($arrOrderTemp);
297        return $this->objFormParam;
298    }
299
300    /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */
301    function lfGetImgShow($arrPayment) {
302        $img_show = false;
303        foreach ($arrPayment as $payment) {
304            if (strlen($payment["payment_image"]) > 0 ){
305                $img_show = true;
306                break;
307            }
308        }
309        return $img_show;
310    }
311}
312?>
Note: See TracBrowser for help on using the repository browser.