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

Revision 20670, 16.8 KB checked in by nanasess, 13 years ago (diff)

#914 (複数のお届け先選択>選択したお届け先に送る>お支払方法選択画面で戻るボタンでお届け先指定画面に戻る)

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