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

Revision 20444, 7.6 KB checked in by shutta, 13 years ago (diff)

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