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

Revision 20344, 8.7 KB checked in by shutta, 13 years ago (diff)

LC_Pageクラスのclass_extends対応。

  • 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");
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_Ex {
38
39    // {{{ properties
40
41    /** セッションの配列 */
42    var $arrSession;
43
44    /** カテゴリの配列 */
45    var $arrProductsClass;
46
47    /** 商品規格情報の配列 */
48    var $arrData;
49
50    /** 動作モード */
51    var $mode;
52
53
54    // }}}
55    // {{{ functions
56
57    /**
58     * Page を初期化する.
59     *
60     * @return void
61     */
62    function init() {
63        parent::init();
64        $this->tpl_title = "現在のカゴの中";
65        $masterData = new SC_DB_MasterData_Ex();
66        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
67
68    }
69
70    /**
71     * Page のプロセス.
72     *
73     * @return void
74     */
75    function process() {
76        parent::process();
77        $this->action();
78        $this->sendResponse();
79    }
80
81    /**
82     * Page のアクション.
83     *
84     * @return void
85     */
86    function action() {
87        $objCartSess = new SC_CartSession();
88        $objSiteSess = new SC_SiteSession();
89        $objSiteInfo = $objView->objSiteInfo;
90        $objCustomer = new SC_Customer();
91       
92        $objFormParam = $this->lfInitParam($_REQUEST);
93        $this->mode = $this->getMode();
94
95        $this->cartKeys = $objCartSess->getKeys();
96        foreach ($this->cartKeys as $key) {
97            // 商品購入中にカート内容が変更された。
98            if($objCartSess->getCancelPurchase($key)) {
99                $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。";
100            }
101        }
102        $this->cartItems =& $objCartSess->getAllCartList();
103
104        $cart_no = $objFormParam->getValue('cart_no');
105        $cartKey = $objFormParam->getValue('cartKey');
106       
107        switch($this->mode) {
108        case 'confirm':
109            // カート内情報の取得
110            $cartList = $objCartSess->getCartList($cartKey);
111            // カート商品が1件以上存在する場合
112            if(count($cartList) > 0) {
113                // カートを購入モードに設定
114                $this->lfSetCurrentCart($objSiteSess,$objCartSess);
115                // 購入ページへ
116                SC_Response_Ex::sendRedirect(SHOPPING_URL);
117                exit;
118            }
119            break;
120        case 'up'://1個追加
121            $objCartSess->upQuantity($cart_no, $cartKey);
122            //SC_Response_Ex::reload();
123            $this->lfReload();
124            break;
125        case 'down'://1個減らす
126            $objCartSess->downQuantity($cart_no, $cartKey);
127            //SC_Response_Ex::reload();
128            $this->lfReload();
129            break;
130        case 'delete'://カートから削除
131            $objCartSess->delProduct($cart_no, $cartKey);
132            //SC_Response_Ex::reload();
133            $this->lfReload();
134            break;
135        default:
136            break;
137        }
138
139        // 基本情報の取得
140        $this->arrInfo = $objSiteInfo->data;
141        foreach ($this->cartKeys as $key) {
142            // カート集計処理
143            $this->tpl_message = $objCartSess->checkProducts($key);
144            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
145            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
146            // ポイント合計
147            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
148
149            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
150            // 送料無料までの金額を計算
151            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
152        }
153
154        // ログイン判定
155        if($objCustomer->isLoginSuccess(true)) {
156            $this->tpl_login = true;
157            $this->tpl_user_point = $objCustomer->getValue('point');
158            $this->tpl_name = $objCustomer->getValue('name01');
159        }
160
161        // 前頁のURLを取得
162        // TODO: SC_CartSession::setPrevURL()利用不可。
163        $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
164
165        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
166    }
167
168    /**
169     * デストラクタ.
170     *
171     * @return void
172     */
173    function destroy() {
174        parent::destroy();
175    }
176   
177
178    /**
179     * ユーザ入力値の処理
180     *
181     * @return object
182     */
183    function lfInitParam($arrRequest) {
184        $objFormParam = new SC_FormParam();
185        $objFormParam->addParam("カートキー", "cartKey", INT_LEN, "n", array('NUM_CHECK',"MAX_LENGTH_CHECK"));
186        $objFormParam->addParam("カートナンバー", "cart_no", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
187        // 値の取得
188        $objFormParam->setParam($arrRequest);
189        // 入力値の変換
190        $objFormParam->convParam();
191        return $objFormParam;       
192    }
193
194    /**
195     * order_temp_id の更新
196     *
197     * @return
198     */   
199    function lfUpdateOrderTempid($pre_uniqid,$uniqid){
200        $sqlval['order_temp_id'] = $uniqid;
201        $where = "order_temp_id = ?";
202        $objQuery =& SC_Query::getSingletonInstance();
203        $res = $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid));
204        if($res != 1){
205            return false;
206        }
207        return true;
208    }
209
210    /**
211     * 前頁のURLを取得
212     *
213     * @return void
214     */       
215    function lfGetCartPrevUrl(&$session,$referer){
216        if (!preg_match("/cart/", $referer)) {
217            if (!empty($session['cart_referer_url'])) {
218                $session['cart_prev_url'] = $session['cart_referer_url'];
219                unset($session['cart_referer_url']);
220            } else {
221                if (preg_match("/entry/", $referer)) {
222                    $session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
223                } else {
224                    $session['cart_prev_url'] = $referer;
225                }
226            }
227        }
228        // 妥当性チェック
229        if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
230            $session['cart_prev_url'] = '';
231        } 
232    }
233   
234    /**
235     * カートを購入モードに設定
236     *
237     * @return void
238     */           
239    function lfSetCurrentCart(&$objSiteSess,&$objCartSess){
240        // 正常に登録されたことを記録しておく
241        $objSiteSess->setRegistFlag();
242        $pre_uniqid = $objSiteSess->getUniqId();
243        // 注文一時IDの発行
244        $objSiteSess->setUniqId();
245        $uniqid = $objSiteSess->getUniqId();
246        // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
247        if($pre_uniqid != "") {
248            $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
249        }
250        // カートを購入モードに設定
251        $objCartSess->saveCurrentCart($uniqid, $cartKey);
252    }
253
254    /**
255     * 端末ごとのリロード処理
256     *
257     * @return void
258     */               
259    function lfReload(){
260        //FIXME SC_Response_Ex::reload()だと携帯で無限リダイレクト
261        if(SC_Display::detectDevice() == DEVICE_TYPE_MOBILE){
262            $_SERVER['REQUEST_URI'] = str_replace("mode=delete","",$_SERVER['REQUEST_URI']);
263            $_SERVER['REQUEST_URI'] = str_replace("mode=up","",$_SERVER['REQUEST_URI']);
264            $_SERVER['REQUEST_URI'] = str_replace("mode=down","",$_SERVER['REQUEST_URI']);
265            $_SERVER['REQUEST_URI'] = str_replace("&&","&",$_SERVER['REQUEST_URI']);
266            $this->objDisplay->reload();
267            exit;
268        }
269        SC_Response_Ex::reload();
270    }
271}
272?>
Note: See TracBrowser for help on using the repository browser.