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

Revision 23396, 18.2 KB checked in by kimoto, 10 years ago (diff)

#2386 ダウンロード商品の場合にwarningが出るのを修正

  • 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-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        if ($arrForm['point_check'] == '1') {
299            $objErr->doFunc(array('ポイントを使用する', 'point_check'), array('EXIST_CHECK'));
300            $objErr->doFunc(array('ポイント', 'use_point'), array('EXIST_CHECK'));
301            if ($max_point == '') {
302                $max_point = 0;
303            }
304            // FIXME mobile 互換のため br は閉じない...
305            if ($arrForm['use_point'] > $max_point) {
306                $objErr->arrErr['use_point'] = '※ ご利用ポイントが所持ポイントを超えています。<br>';
307            }
308            if (($arrForm['use_point'] * POINT_VALUE) > $subtotal) {
309                $objErr->arrErr['use_point'] = '※ ご利用ポイントがご購入金額を超えています。<br>';
310            }
311            // ポイント差し引き後のお支払い方法チェック
312            $objPayment = new SC_Helper_Payment_Ex();
313            $arrPayments = $objPayment->get($arrForm['payment_id']);
314            if ($arrPayments['rule_max'] > $subtotal - $arrForm['use_point'] * POINT_VALUE) {
315                $objErr->arrErr['use_point'] = '※ 選択したお支払い方法では、ポイントは'.($subtotal - $arrPayments['rule_max']).'ポイントまでご利用いただけます。<br>';
316            }
317        }
318
319        return $objErr->arrErr;
320    }
321
322    /**
323     * 配送情報を保存する.
324     *
325     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
326     * @param array        $arrDelivTime 配送時間の配列
327     */
328    public function saveShippings(&$objFormParam, $arrDelivTime)
329    {
330        // ダウンロード商品の場合は配送先が存在しない
331        if ($this->is_download) return;
332
333        $deliv_id = $objFormParam->getValue('deliv_id');
334        /* TODO
335         * SC_Purchase::getShippingTemp() で取得して,
336         * リファレンスで代入すると, セッションに添字を追加できない?
337         */
338        foreach (array_keys($_SESSION['shipping']) as $key) {
339            $shipping_id = $_SESSION['shipping'][$key]['shipping_id'];
340            $time_id = $objFormParam->getValue('deliv_time_id' . $shipping_id);
341            $_SESSION['shipping'][$key]['deliv_id'] = $deliv_id;
342            $_SESSION['shipping'][$key]['time_id'] = $time_id;
343            $_SESSION['shipping'][$key]['shipping_time'] = $arrDelivTime[$time_id];
344            $_SESSION['shipping'][$key]['shipping_date'] = $objFormParam->getValue('deliv_date' . $shipping_id);
345        }
346    }
347
348    /**
349     * 受注一時テーブルへ登録を行う.
350     *
351     * @param  integer            $uniqid      受注一時テーブルのユニークID
352     * @param  array              $arrForm     フォームの入力値
353     * @param  SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
354     * @param  array              $arrPayment  お支払い方法の配列
355     * @return void
356     */
357    public function lfRegistData($uniqid, $arrForm, &$objPurchase, $arrPayment)
358    {
359        $arrForm['order_temp_id'] = $uniqid;
360        $arrForm['update_date'] = 'CURRENT_TIMESTAMP';
361
362        if ($arrForm['point_check'] != '1') {
363            $arrForm['use_point'] = 0;
364        }
365
366        foreach ($arrPayment as $payment) {
367            if ($arrForm['payment_id'] == $payment['payment_id']) {
368                $arrForm['charge'] = $payment['charge'];
369                $arrForm['payment_method'] = $payment['payment_method'];
370                break;
371            }
372        }
373        $objPurchase->saveOrderTemp($uniqid, $arrForm);
374    }
375
376    /**
377     * 配送業者IDから, 支払い方法, お届け時間の配列を取得する.
378     *
379     * 結果の連想配列の添字の値は以下の通り
380     * - 'arrDelivTime' - お届け時間の配列
381     * - 'arrPayment' - 支払い方法の配列
382     * - 'img_show' - 支払い方法の画像の有無
383     *
384     * @param  SC_CartSession $objCartSess SC_CartSession インスタンス
385     * @param  integer        $deliv_id    配送業者ID
386     * @return array          支払い方法, お届け時間を格納した配列
387     */
388    public function getSelectedDeliv(&$objCartSess, $deliv_id)
389    {
390        $arrResults = array();
391        $arrResults['arrDelivTime'] = SC_Helper_Delivery_Ex::getDelivTime($deliv_id);
392        $total = $objCartSess->getAllProductsTotal($objCartSess->getKey());
393        $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id);
394        $objPayment = new SC_Helper_Payment_Ex();
395        $payments_total = $objPayment->getByPrice($total);
396        $arrPayment = array();
397        foreach ($payments_total as $payment) {
398            if (in_array($payment['payment_id'], $payments_deliv)) {
399                $arrPayment[] = $payment;
400            }
401        }
402        $arrResults['arrPayment'] = $arrPayment;
403        $arrResults['img_show'] = $this->hasPaymentImage($arrResults['arrPayment']);
404
405        return $arrResults;
406    }
407
408    /**
409     * 支払い方法の画像があるかどうか.
410     *
411     * @param  array   $arrPayment 支払い方法の配列
412     * @return boolean 支払い方法の画像がある場合 true
413     */
414    public function hasPaymentImage($arrPayment)
415    {
416        foreach ($arrPayment as $val) {
417            if (!SC_Utils_Ex::isBlank($val['payment_image'])) {
418                return true;
419            }
420        }
421
422        return false;
423    }
424
425    /**
426     * 配送業者が1社のみかどうか.
427     *
428     * @param  array   $arrDeliv 配送業者の配列
429     * @return boolean 配送業者が1社のみの場合 true
430     */
431    public function isSingleDeliv($arrDeliv)
432    {
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    public function getMobileMainpage($is_single_deliv = true, $mode)
448    {
449        switch ($mode) {
450            case 'select_deliv':
451                return 'shopping/payment.tpl';
452
453            case 'confirm':
454            case 'return':
455            default:
456                if ($is_single_deliv) {
457                    return 'shopping/payment.tpl';
458                } else {
459                    return 'shopping/select_deliv.tpl';
460                }
461                break;
462        }
463    }
464}
Note: See TracBrowser for help on using the repository browser.