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

Revision 21006, 17.3 KB checked in by Seasoft, 13 years ago (diff)

#1361 (お届け先の複数指定 実際に配送で使わないお届け先も保持される(非会員))
#1368 (お届け先の複数指定 配送先変更のはずが配送先と注文数が増える)
#1386 (「お届け先の複数指定」か否かに関わらず、配送商品を登録する)

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