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

Revision 20116, 16.5 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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_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();";
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        $objCustomer = new SC_Customer();
81        $objFormParam = new SC_FormParam();
82
83        // カートの情報を取得
84        $this->arrShipping =& $objPurchase->getShippingTemp();
85        $shipping_vol = count($this->arrShipping);
86
87        $this->is_multiple = $objPurchase->isMultiple();
88        $this->tpl_uniqid = $objSiteSess->getUniqId();
89        $cart_key = $objCartSess->getKey();
90        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
91
92        // 配送業者を取得
93        $this->arrDeliv = $objPurchase->getDeliv($cart_key);
94        $this->is_single_deliv = $this->isSingleDeliv($this->arrDeliv);
95
96        // 会員情報の取得
97        if ($objCustomer->isLoginSuccess(true)) {
98            $this->tpl_login = '1';
99            $this->tpl_user_point = $objCustomer->getValue('point');
100            $this->name01 = $objCustomer->getValue('name01');
101            $this->name02 = $objCustomer->getValue('name02');
102        }
103
104        // 戻り URL の設定
105        $this->tpl_back_url = $this->getPreviousURL($objCustomer->isLoginSuccess(true), $cart_key);
106
107        $arrOrderTemp = $objPurchase->getOrderTemp($this->tpl_uniqid);
108        // 正常に受注情報が格納されていない場合はカート画面へ戻す
109        if (SC_Utils_Ex::isBlank($arrOrderTemp)) {
110            SC_Response_Ex::sendRedirect(CART_URLPATH);
111            exit;
112        }
113
114        // カート内商品の妥当性チェック
115        $this->tpl_message = $objCartSess->checkProducts($cart_key);
116        if (strlen($this->tpl_message) >= 1) {
117            SC_Response_Ex::sendRedirect(CART_URLPATH);
118            exit;
119        }
120
121        // 購入金額の取得
122        $this->arrPrices = $objCartSess->calculate($cart_key, $objCustomer, 0, $objPurchase->getShippingPref());
123
124        // お届け日一覧の取得
125        $this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $cart_key);
126
127        switch($this->getMode()) {
128        /*
129         * 配送業者選択時のアクション
130         * モバイル端末以外の場合は, JSON 形式のデータを出力し, ajax で取得する.
131         */
132        case 'select_deliv':
133            $this->setFormParams($objFormParam, $_POST, true, $shipping_vol);
134
135            $arrErr = $objFormParam->checkError();
136            if (SC_Utils_Ex::isBlank($arrErr)) {
137                $deliv_id = $objFormParam->getValue('deliv_id');
138                $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
139                $arrSelectedDeliv['error'] = false;
140            } else {
141                $arrSelectedDeliv = array('error' => true);
142            }
143
144            if (SC_Display::detectDevice() != DEVICE_TYPE_MOBILE) {
145                $objJson = new Services_JSON();
146                echo $objJson->encode($arrSelectedDeliv);
147                exit;
148            } else {
149                $this->arrPayment = $arrSelectedDeliv['arrPayment'];
150                $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
151            }
152            break;
153
154        // 登録処理
155        case 'confirm':
156            // パラメータ情報の初期化
157            $this->setFormParams($objFormParam, $_POST, false, $shipping_vol);
158
159            $deliv_id = $objFormParam->getValue('deliv_id');
160            $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
161            $this->arrPayment = $arrSelectedDeliv['arrPayment'];
162            $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
163
164            $this->arrErr = $this->lfCheckError($objFormParam, $this->arrPrices['subtotal'], $this->tpl_user_point);
165
166            if (SC_Utils_Ex::isBlank($this->arrErr)) {
167                $this->saveShippings($objFormParam, $this->arrDelivTime);
168                $this->lfRegistData($this->tpl_uniqid, $objFormParam->getDbArray(), $objPurchase, $this->arrPayment);
169
170                // 正常に登録されたことを記録しておく
171                $objSiteSess->setRegistFlag();
172                // 確認ページへ移動
173                SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URLPATH);
174                exit;
175            } else {
176                // 受注一時テーブルからの情報を格納
177                $this->img_show = $arrSelectedDeliv['img_show'];
178                $objFormParam->setParam($objPurchase->getOrderTemp($this->tpl_uniqid));
179            }
180            break;
181
182        // 前のページに戻る
183        case 'return':
184
185            // 正常な推移であることを記録しておく
186            $objSiteSess->setRegistFlag();
187            SC_Response_Ex::sendRedirect(SHOPPING_URL);
188            exit;
189            break;
190
191        default:
192            // 前のページから戻ってきた場合の初期値を設定
193            $this->setFormParams($objFormParam, $arrOrderTemp, true, $shipping_vol);
194
195            if (!$this->is_single_deliv) {
196                $deliv_id = $objFormParam->getValue('deliv_id');
197            }
198
199            if (!SC_Utils_Ex::isBlank($deliv_id)) {
200                $objFormParam->setValue('deliv_id', $deliv_id);
201                $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
202                $this->arrPayment = $arrSelectedDeliv['arrPayment'];
203                // XXX セッションからデフォルト値を取得する必要あり
204                $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
205                $this->img_show = $arrSelectedDeliv['img_show'];
206            }
207            break;
208        }
209
210        // モバイル用 ポストバック処理
211        if (SC_Display::detectDevice() == DEVICE_TYPE_MOBILE) {
212            $this->tpl_mainpage = $this->getMobileMainpage($this->is_single_deliv, $this->getMode());
213        }
214
215        $this->arrForm = $objFormParam->getFormParamList();
216    }
217
218    /**
219     * デストラクタ.
220     *
221     * @return void
222     */
223    function destroy() {
224        parent::destroy();
225    }
226
227    /**
228     * パラメータの初期化を行い, 初期値を設定する.
229     *
230     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
231     * @param array $arrParam 設定する値の配列
232     * @param boolean $deliv_only deliv_id チェックのみの場合 true
233     * @param integer $shipping_vol 配送数
234     */
235    function setFormParams(&$objFormParam, $arrParam, $deliv_only = false, $shipping_vol) {
236        $this->lfInitParam($objFormParam, $deliv_only, $shipping_vol);
237        $objFormParam->setParam($arrParam);
238        $objFormParam->convParam();
239    }
240
241    /**
242     * パラメータ情報の初期化を行う.
243     *
244     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
245     * @param boolean $deliv_only deliv_id チェックのみの場合 true
246     * @param integer $shipping_vol 配送数
247     * @return void
248     */
249    function lfInitParam(&$objFormParam, $deliv_only = false, $shipping_vol) {
250        $objFormParam->addParam("配送業者", "deliv_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
251
252        if (!$deliv_only) {
253            $objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
254            $objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
255            $objFormParam->addParam("その他お問い合わせ", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
256            $objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
257
258            for ($i = 0; $i < $shipping_vol; $i++) {
259                $objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
260                $objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
261            }
262        }
263
264        $objFormParam->setParam($arrParam);
265        $objFormParam->convParam();
266    }
267
268    /**
269     * 入力内容のチェックを行なう.
270     *
271     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
272     * @param integer $subtotal 購入金額の小計
273     * @param integer $max_point 会員の保持ポイント
274     * @return array 入力チェック結果の配列
275     */
276    function lfCheckError(&$objFormParam, $subtotal, $max_point) {
277        // 入力データを渡す。
278        $arrForm =  $objFormParam->getHashArray();
279        $objErr = new SC_CheckError($arrForm);
280        $objErr->arrErr = $objFormParam->checkError();
281
282        if (USE_POINT === false) {
283            return $objErr->arrErr;
284        }
285
286        if($arrForm['point_check'] == '1') {
287            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
288            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
289            if($max_point == "") {
290                $max_point = 0;
291            }
292            // FIXME mobile 互換のため br は閉じない...
293            if($arrForm['use_point'] > $max_point) {
294                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
295            }
296            if(($arrForm['use_point'] * POINT_VALUE) > $subtotal) {
297                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
298            }
299        }
300        return $objErr->arrErr;
301    }
302
303    /**
304     * 配送情報を保存する.
305     *
306     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
307     * @param array $arrDelivTime 配送時間の配列
308     */
309    function saveShippings(&$objFormParam, $arrDelivTime) {
310        $deliv_id = $objFormParam->getValue('deliv_id');
311
312        /* TODO
313         * SC_Purchase::getShippingTemp() で取得して,
314         * リファレンスで代入すると, セッションに添字を追加できない?
315         */
316        foreach (array_keys($_SESSION['shipping']) as $key) {
317
318            $time_id = $objFormParam->getValue('deliv_time_id' . $key);
319
320            $_SESSION['shipping'][$key]['deliv_id'] = $deliv_id;
321            $_SESSION['shipping'][$key]['time_id'] = $time_id;
322            $_SESSION['shipping'][$key]['shipping_time'] = $arrDelivTime[$time_id];
323            $_SESSION['shipping'][$key]['shipping_date'] = $objFormParam->getValue('deliv_date' . $key);
324        }
325    }
326
327    /**
328     * 受注一時テーブルへ登録を行う.
329     *
330     * @param integer $uniqid 受注一時テーブルのユニークID
331     * @param array $arrForm フォームの入力値
332     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
333     * @param array $arrPayment お支払い方法の配列
334     * @return void
335     */
336    function lfRegistData($uniqid, $arrForm, &$objPurchase, $arrPayment) {
337
338        $arrForm['order_temp_id'] = $uniqid;
339        $arrForm['update_date'] = 'Now()';
340
341        if($arrForm['point_check'] != '1') {
342            $arrForm['use_point'] = 0;
343        }
344
345        foreach ($arrPayment as $payment) {
346            if ($arrForm['payment_id'] == $payment['payment_id']) {
347                $arrForm['charge'] = $payment['charge'];
348                $arrForm['payment_method'] = $payment['payment_method'];
349                break;
350            }
351        }
352        $objPurchase->saveOrderTemp($uniqid, $arrForm);
353    }
354
355    /**
356     * 配送業者IDから, 支払い方法, お届け時間の配列を取得する.
357     *
358     * 結果の連想配列の添字の値は以下の通り
359     * - 'arrDelivTime' - お届け時間の配列
360     * - 'arrPayment' - 支払い方法の配列
361     * - 'img_show' - 支払い方法の画像の有無
362     *
363     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
364     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
365     * @param integer $deliv_id 配送業者ID
366     * @return array 支払い方法, お届け時間を格納した配列
367     */
368    function getSelectedDeliv(&$objPurchase, &$objCartSess, $deliv_id) {
369        $arrResults = array();
370        $arrResults['arrDelivTime'] = $objPurchase->getDelivTime($deliv_id);
371        $total = $objCartSess->getAllProductsTotal($objCartSess->getKey(),
372                                                   $deliv_id);
373        $arrResults['arrPayment'] = $objPurchase->getPaymentsByPrice($total,
374                                                                     $deliv_id);
375        $arrResults['img_show'] = $this->hasPaymentImage($arrResults['arrPayment']);
376        return $arrResults;
377    }
378
379    /**
380     * 支払い方法の画像があるかどうか.
381     *
382     * @param array $arrPayment 支払い方法の配列
383     * @return boolean 支払い方法の画像がある場合 true
384     */
385    function hasPaymentImage($arrPayment) {
386        foreach ($arrPayment as $val) {
387            if (!SC_Utils_Ex::isBlank($val['payment_image'])) {
388                return true;
389            }
390        }
391        return false;
392    }
393
394    /**
395     * 配送業者が1社のみかどうか.
396     *
397     * @param array $arrDeliv 配送業者の配列
398     * @return boolean 配送業者が1社のみの場合 true
399     */
400    function isSingleDeliv($arrDeliv) {
401        if (count($arrDeliv) == 1) {
402            return true;
403        } else {
404            return false;
405        }
406    }
407
408    /**
409     * 前に戻るボタンの URL を取得する.
410     *
411     * @param boolean $is_login ユーザーがログインしている場合 true
412     * @param $product_type_id 商品種別ID
413     * @return string 前に戻るボタンの URL
414     */
415    function getPreviousURL($is_login = false, $product_type_id) {
416        if ($is_login) {
417            if ($product_type_id == PRODUCT_TYPE_DOWNLOAD) {
418                return CART_URLPATH;
419            } else {
420                return DELIV_URLPATH;
421            }
422        } else {
423            return SHOPPING_URL . "?from=nonmember";
424        }
425    }
426
427    /**
428     * モバイル用テンプレートのパスを取得する.
429     *
430     * @param boolean $is_single_deliv 配送業者が1社の場合 true
431     * @param string $mode フォームパラメータ "mode" の文字列
432     * @return string モバイル用テンプレートのパス
433     */
434    function getMobileMainpage($is_single_deliv = true, $mode) {
435        switch($mode) {
436        case 'select_deliv':
437            return 'shopping/payment.tpl';
438            break;
439
440        case 'confirm':
441        case 'return':
442        default:
443            if ($is_single_deliv) {
444                return 'shopping/payment.tpl';
445            } else {
446                return 'shopping/select_deliv.tpl';
447            }
448        }
449    }
450}
451?>
Note: See TracBrowser for help on using the repository browser.