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

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

Revision 23462, 18.3 KB checked in by shutta, 10 years ago (diff)

#2561 購入時のポイント使用欄にて、文字を入力した際のエラーがおかしい
基本の入力値チェックが通らないと、使用ポイント数の詳細チェックを行なわないように修正。

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