source: branches/version-2_5-dev/data/class/pages/cart/LC_Page_Cart.php @ 20044

Revision 20044, 7.7 KB checked in by eccuore, 13 years ago (diff)

#642(共通ロジックの機能向上) mode 取得用の関数を利用するように修正ミス(switchリファクタリングは一部対応)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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_REALDIR . "pages/LC_Page.php");
26if (file_exists(MODULE_REALDIR . "mdl_gmopg/inc/function.php")) {
27    require_once(MODULE_REALDIR . "mdl_gmopg/inc/function.php");
28}
29
30/**
31 * カート のページクラス.
32 *
33 * @package Page
34 * @author LOCKON CO.,LTD.
35 * @version $Id$
36 */
37class LC_Page_Cart extends LC_Page {
38
39    // {{{ properties
40
41    /** セッションの配列 */
42    var $arrSession;
43
44    /** カテゴリの配列 */
45    var $arrProductsClass;
46
47    /** 商品規格情報の配列 */
48    var $arrData;
49
50    // }}}
51    // {{{ functions
52
53    /**
54     * Page を初期化する.
55     *
56     * @return void
57     */
58    function init() {
59        parent::init();
60        $this->tpl_title = "現在のカゴの中";
61        $masterData = new SC_DB_MasterData_Ex();
62        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
63
64    }
65
66    /**
67     * Page のプロセス.
68     *
69     * @return void
70     */
71    function process() {
72        parent::process();
73        $this->action();
74        $this->sendResponse();
75    }
76
77    /**
78     * Page のアクション.
79     *
80     * @return void
81     */
82    function action() {
83        $objView = new SC_SiteView(false);
84        $objCartSess = new SC_CartSession();
85        $objSiteSess = new SC_SiteSession();
86        $objSiteInfo = $objView->objSiteInfo;
87        $objCustomer = new SC_Customer();
88
89        $this->cartKeys = $objCartSess->getKeys();
90        foreach ($this->cartKeys as $key) {
91            // 商品購入中にカート内容が変更された。
92            if($objCartSess->getCancelPurchase($key)) {
93                $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。";
94            }
95        }
96        $this->cartItems =& $objCartSess->getAllCartList();
97
98        //TODO: 要リファクタリング(MODE switch 2か所で行われている)
99        switch($this->getMode()) {
100        case 'confirm':
101            // カート内情報の取得
102            $cartKey = $_POST['cartKey'];
103            $cartList = $objCartSess->getCartList($cartKey);
104            // カート商品が1件以上存在する場合
105            if(count($cartList) > 0) {
106                // 正常に登録されたことを記録しておく
107                $objSiteSess->setRegistFlag();
108                $pre_uniqid = $objSiteSess->getUniqId();
109                // 注文一時IDの発行
110                $objSiteSess->setUniqId();
111                $uniqid = $objSiteSess->getUniqId();
112                // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
113                if($pre_uniqid != "") {
114                    $sqlval['order_temp_id'] = $uniqid;
115                    $where = "order_temp_id = ?";
116                    $objQuery = new SC_Query();
117                    $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid));
118                }
119                // カートを購入モードに設定
120                $objCartSess->saveCurrentCart($uniqid, $cartKey);
121                // 購入ページへ
122                SC_Response_Ex::sendRedirect(SHOPPING_URL);
123                exit;
124            }
125            break;
126        default:
127            break;
128        }
129
130        // 商品の個数変更、削除処理
131        /*
132         * FIXME モバイルの場合 sfReload() ではなく sendRedirect() を使った方が良いが無限ループしてしまう...
133         */
134        //TODO: 要リファクタリング(MODE switch 2か所で行われている)
135        switch($this->getMode()) {
136        case 'up':
137            if(Net_UserAgent_Mobile::isMobile() === true) {
138                $objCartSess->upQuantity($_GET['cart_no'], $_GET['cartKey']);
139                SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
140            } else {
141                $objCartSess->upQuantity($_POST['cart_no'], $_POST['cartKey']);
142                $this->objDisplay->reload(); // PRG pattern
143            }
144            break;
145        case 'down':
146            if(Net_UserAgent_Mobile::isMobile() === true) {
147                $objCartSess->downQuantity($_GET['cart_no'], $_GET['cartKey']);
148                SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
149            } else {
150                $objCartSess->downQuantity($_POST['cart_no'], $_POST['cartKey']);
151                $this->objDisplay->reload(); // PRG pattern
152            }
153            break;
154        case 'delete':
155            if(Net_UserAgent_Mobile::isMobile() === true) {
156                $objCartSess->delProduct($_GET['cart_no'], $_GET['cartKey']);
157                SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
158            } else {
159                $objCartSess->delProduct($_POST['cart_no'], $_POST['cartKey']);
160                $this->objDisplay->reload(); // PRG pattern
161            }
162            break;
163        default:
164            break;
165        }
166
167        // 基本情報の取得
168        $this->arrInfo = $objSiteInfo->data;
169        foreach ($this->cartKeys as $key) {
170            // カート集計処理
171            $this->tpl_message = $objCartSess->checkProducts($key);
172            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
173            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
174            // ポイント合計
175            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
176
177            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
178            // 送料無料までの金額を計算
179            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
180        }
181
182        // ログイン判定
183        if($objCustomer->isLoginSuccess(true)) {
184            $this->tpl_login = true;
185            $this->tpl_user_point = $objCustomer->getValue('point');
186            $this->tpl_name = $objCustomer->getValue('name01');
187        }
188
189        // 前頁のURLを取得
190        // TODO: SC_CartSession::setPrevURL()利用不可。
191        if (!preg_match("/cart/", $_SERVER['HTTP_REFERER'])) {
192            if (!empty($_SESSION['cart_referer_url'])) {
193                $_SESSION['cart_prev_url'] = $_SESSION['cart_referer_url'];
194                unset($_SESSION['cart_referer_url']);
195            } else {
196                if (preg_match("/entry/", $_SERVER['HTTP_REFERER'])) {
197                    $_SESSION['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
198                } else {
199                    $_SESSION['cart_prev_url'] = $_SERVER['HTTP_REFERER'];
200                }
201            }
202        }
203        // 妥当性チェック
204        if (!SC_Utils_Ex::sfIsInternalDomain($_SESSION['cart_prev_url'])) {
205            $_SESSION['cart_prev_url'] = '';
206        }
207
208        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
209    }
210
211    /**
212     * デストラクタ.
213     *
214     * @return void
215     */
216    function destroy() {
217        parent::destroy();
218    }
219}
220?>
Note: See TracBrowser for help on using the repository browser.