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

Revision 21596, 10.7 KB checked in by Seasoft, 12 years ago (diff)

#1613 (typo修正・ソース整形・ソースコメントの改善)

  • 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_Cart extends LC_Page_Ex {
35
36    // {{{ properties
37
38    /** 商品規格情報の配列 */
39    var $arrData;
40
41    /** 動作モード */
42    var $mode;
43
44    // }}}
45    // {{{ functions
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    function init() {
53        parent::init();
54        $this->tpl_title = '現在のカゴの中';
55        $masterData = new SC_DB_MasterData_Ex();
56        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
57
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        // フックポイント.
78        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
79        $objPlugin->doAction('lc_page_cart_action_start', array($this));
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 = '商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。';
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                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
110                    $objPlugin->doAction('lc_page_cart_action_confirm', array($this));
111
112                    // 購入ページへ
113                    SC_Response_Ex::sendRedirect(SHOPPING_URL);
114                    exit;
115                }
116                break;
117            case 'up'://1個追加
118                $objCartSess->upQuantity($cart_no, $cartKey);
119
120                // フックポイント.
121                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
122                $objPlugin->doAction('lc_page_cart_action_up', array($this));
123
124                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
125                exit;
126                break;
127            case 'down'://1個減らす
128                $objCartSess->downQuantity($cart_no, $cartKey);
129
130                // フックポイント.
131                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
132                $objPlugin->doAction('lc_page_cart_action_down', array($this));
133
134                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
135                exit;
136                break;
137            case 'setQuantity'://数量変更
138                $objCartSess->setQuantity($objFormParam->getValue('quantity'), $cart_no, $cartKey);
139
140                // フックポイント.
141                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
142                $objPlugin->doAction('lc_page_cart_action_setQuantity', array($this));
143
144                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
145                exit;
146                break;
147            case 'delete'://カートから削除
148                $objCartSess->delProduct($cart_no, $cartKey);
149
150                // フックポイント.
151                $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
152                $objPlugin->doAction('lc_page_cart_action_delete', array($this));
153
154                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
155                exit;
156                break;
157            default:
158                break;
159        }
160        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
161        $totalIncTax = 0;
162        foreach (array_keys($this->cartKeys) as $index) {
163            $key = $this->cartKeys[$index];
164            // カート集計処理
165            $this->tpl_message = $objCartSess->checkProducts($key);
166            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
167            $totalIncTax += $this->tpl_total_inctax[$key];
168            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
169            // ポイント合計
170            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
171
172            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
173
174            // 送料無料チェック
175            $this->arrData[$key]['is_deliv_free'] = $objCartSess->isDelivFree($key);
176
177            // 送料無料までの金額を計算
178            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
179            if (SC_Utils_Ex::isBlank($key)) {
180                unset($this->cartKeys[$index]);
181            }
182        }
183
184        //商品の合計金額をセット
185        $this->tpl_all_total_inctax = $totalIncTax;
186
187        $this->tpl_category_id = $objFormParam->getValue('category_id');
188
189        // ログイン判定
190        if ($objCustomer->isLoginSuccess(true)) {
191            $this->tpl_login = true;
192            $this->tpl_user_point = $objCustomer->getValue('point');
193            $this->tpl_name = $objCustomer->getValue('name01');
194        }
195
196        // 前頁のURLを取得
197        // TODO: SC_CartSession::setPrevURL()利用不可。
198        $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
199        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
200
201        // すべてのカートの内容を取得する
202        $this->cartItems = $objCartSess->getAllCartList();
203
204        // フックポイント.
205        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
206        $objPlugin->doAction('lc_page_cart_action_end', array($this));
207    }
208
209    /**
210     * デストラクタ.
211     *
212     * @return void
213     */
214    function destroy() {
215        parent::destroy();
216    }
217
218    /**
219     * ユーザ入力値の処理
220     *
221     * @return object
222     */
223    function lfInitParam($arrRequest) {
224        $objFormParam = new SC_FormParam_Ex();
225        $objFormParam->addParam('カートキー', 'cartKey', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
226        $objFormParam->addParam('カートナンバー', 'cart_no', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
227        // PC版での値引き継ぎ用
228        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
229        // スマートフォン版での数量変更用
230        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
231        // 値の取得
232        $objFormParam->setParam($arrRequest);
233        // 入力値の変換
234        $objFormParam->convParam();
235        return $objFormParam;
236    }
237
238    /**
239     * order_temp_id の更新
240     *
241     * @return
242     */
243    function lfUpdateOrderTempid($pre_uniqid,$uniqid) {
244        $sqlval['order_temp_id'] = $uniqid;
245        $where = 'order_temp_id = ?';
246        $objQuery =& SC_Query_Ex::getSingletonInstance();
247        $res = $objQuery->update('dtb_order_temp', $sqlval, $where, array($pre_uniqid));
248        if ($res != 1) {
249            return false;
250        }
251        return true;
252    }
253
254    /**
255     * 前頁のURLを取得
256     *
257     * @return void
258     */
259    function lfGetCartPrevUrl(&$session,$referer) {
260        if (!preg_match('/cart/', $referer)) {
261            if (!empty($session['cart_referer_url'])) {
262                $session['cart_prev_url'] = $session['cart_referer_url'];
263                unset($session['cart_referer_url']);
264            } else {
265                if (preg_match('/entry/', $referer)) {
266                    $session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
267                } else {
268                    $session['cart_prev_url'] = $referer;
269                }
270            }
271        }
272        // 妥当性チェック
273        if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
274            $session['cart_prev_url'] = '';
275        }
276    }
277
278    /**
279     * カートを購入モードに設定
280     *
281     * @return void
282     */
283    function lfSetCurrentCart(&$objSiteSess, &$objCartSess, $cartKey) {
284        // 正常に登録されたことを記録しておく
285        $objSiteSess->setRegistFlag();
286        $pre_uniqid = $objSiteSess->getUniqId();
287        // 注文一時IDの発行
288        $objSiteSess->setUniqId();
289        $uniqid = $objSiteSess->getUniqId();
290        // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
291        if ($pre_uniqid != '') {
292            $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
293        }
294        // カートを購入モードに設定
295        $objCartSess->registerKey($cartKey);
296        $objCartSess->saveCurrentCart($uniqid, $cartKey);
297    }
298}
Note: See TracBrowser for help on using the repository browser.