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

Revision 22090, 9.0 KB checked in by Seasoft, 11 years ago (diff)

#1903 (無駄な処理を改善する)

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