Warning: Can't use blame annotator:
svn blame failed on branches/version-2_12-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php: バイナリファイル 'file:///home/svn/open/branches/version-2_12-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php' に対しては blame で各行の最終変更者を計算できません 195004

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

Revision 22538, 17.7 KB checked in by pineray, 11 years ago (diff)

#2044 getAllProductsTotal関数の第2引数は不要なので削除

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