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

Revision 21629, 18.8 KB checked in by Seasoft, 12 years ago (diff)

#1439 (「お届け先の指定」に戻った際に、選択した状態を引き継いでいない)

  • 実装誤りの修正

#1672 (非会員購入時「お届け先の複数指定」から戻るボタンで遷移すると追加したお届け先が削除される)

  • 実装誤りの修正

#1675 (「お届け先の複数指定」画面での入力内容が復元されない)
#1315 (複数のお届け先関連のキー情報が怪しい)

  • 根本的な解決ではありませんが、とりあえず会員に関しては other_deliv_id を使うようにした。

#1613 (typo修正・ソース整形・ソースコメントの改善)

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