source: branches/version-2_13_3/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 23671

Revision 23671, 18.6 KB checked in by shinichi_takahashi, 9 years ago (diff)

#2453 支払方法・お届け先時間の指定画面のdeliv_idに数値チェックが行われていない に伴う修正

確認画面でお支払方法・お届け先時間が正しく表示されなくなっていた

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