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

Revision 22856, 10.7 KB checked in by Seasoft, 11 years ago (diff)

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

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * カート のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Cart extends LC_Page_Ex
34{
35    /** 商品規格情報の配列 */
36    var $arrData;
37
38    /** 動作モード */
39    var $mode;
40
41    /** メッセージ */
42    public $tpl_message = '';
43
44
45    /**
46     * Page を初期化する.
47     *
48     * @return void
49     */
50    function init()
51    {
52        parent::init();
53        $this->tpl_title = '現在のカゴの中';
54        $masterData = new SC_DB_MasterData_Ex();
55        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
56
57    }
58
59    /**
60     * Page のプロセス.
61     *
62     * @return void
63     */
64    function process()
65    {
66        parent::process();
67        $this->action();
68        $this->sendResponse();
69    }
70
71    /**
72     * Page のアクション.
73     *
74     * @return void
75     */
76    function action()
77    {
78        $objCartSess = new SC_CartSession_Ex();
79        $objSiteSess = new SC_SiteSession_Ex();
80        $objCustomer = new SC_Customer_Ex();
81
82        $objFormParam = $this->lfInitParam($_POST);
83        $this->mode = $this->getMode();
84
85        // モバイル対応
86        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
87            if (isset($_GET['cart_no'])) {
88                $objFormParam->setValue('cart_no', $_GET['cart_no']);
89            }
90            if (isset($_GET['cartKey'])) {
91                $objFormParam->setValue('cartKey', $_GET['cartKey']);
92            }
93        }
94
95        $this->cartKeys = $objCartSess->getKeys();
96        foreach ($this->cartKeys as $key) {
97            // 商品購入中にカート内容が変更された。
98            if ($objCartSess->getCancelPurchase($key)) {
99                $this->tpl_message .= "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。\n";
100            }
101        }
102
103        $cart_no = $objFormParam->getValue('cart_no');
104        $cartKey = $objFormParam->getValue('cartKey');
105
106        // エラーチェック
107        $arrError = $objFormParam->checkError();
108        if(isset($arrError) && !empty($arrError)) {
109            SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND);
110            SC_Response_Ex::actionExit();
111        }
112
113        $objFormParam4OpenCategoryTree =
114            $this->lfInitParam4OpenCategoryTree($_REQUEST);
115        if ($objFormParam4OpenCategoryTree->getValue('product_id')) {
116            $arrQueryString = array(
117                'product_id' => $objFormParam4OpenCategoryTree->getValue(
118                    'product_id'),
119            );
120        } else {
121            $arrQueryString = array(
122                'category_id' => $objFormParam4OpenCategoryTree->getValue(
123                    'category_id'),
124            );
125        }
126
127        switch ($this->mode) {
128            case 'confirm':
129                // カート内情報の取得
130                $cartList = $objCartSess->getCartList($cartKey);
131                // カート商品が1件以上存在する場合
132                if (count($cartList) > 0) {
133                    // カートを購入モードに設定
134                    $this->lfSetCurrentCart($objSiteSess, $objCartSess, $cartKey);
135
136
137                    // 購入ページへ
138                    SC_Response_Ex::sendRedirect(SHOPPING_URL);
139                    SC_Response_Ex::actionExit();
140                }
141                break;
142            case 'up'://1個追加
143                $objCartSess->upQuantity($cart_no, $cartKey);
144
145                SC_Response_Ex::reload($arrQueryString, true);
146                SC_Response_Ex::actionExit();
147                break;
148            case 'down'://1個減らす
149                $objCartSess->downQuantity($cart_no, $cartKey);
150
151                SC_Response_Ex::reload($arrQueryString, true);
152                SC_Response_Ex::actionExit();
153                break;
154            case 'setQuantity'://数量変更
155                $objCartSess->setQuantity($objFormParam->getValue('quantity'), $cart_no, $cartKey);
156
157                SC_Response_Ex::reload($arrQueryString, true);
158                SC_Response_Ex::actionExit();
159                break;
160            case 'delete'://カートから削除
161                $objCartSess->delProduct($cart_no, $cartKey);
162
163                SC_Response_Ex::reload($arrQueryString, true);
164                SC_Response_Ex::actionExit();
165                break;
166            default:
167                break;
168        }
169        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
170        $totalIncTax = 0;
171        foreach ($this->cartKeys as $key) {
172            // カート集計処理
173            $this->tpl_message .= $objCartSess->checkProducts($key);
174            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
175            $totalIncTax += $this->tpl_total_inctax[$key];
176            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
177            // ポイント合計
178            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
179
180            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
181
182            // 送料無料チェック
183            $this->arrData[$key]['is_deliv_free'] = $objCartSess->isDelivFree($key);
184
185            // 送料無料までの金額を計算
186            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
187        }
188
189        //商品の合計金額をセット
190        $this->tpl_all_total_inctax = $totalIncTax;
191
192        $this->tpl_category_id =
193            $objFormParam4OpenCategoryTree->getValue('category_id');
194        $this->tpl_product_id =
195            $objFormParam4OpenCategoryTree->getValue('product_id');
196
197        // ログイン判定
198        if ($objCustomer->isLoginSuccess(true)) {
199            $this->tpl_login = true;
200            $this->tpl_user_point = $objCustomer->getValue('point');
201            $this->tpl_name = $objCustomer->getValue('name01');
202        }
203
204        // 前頁のURLを取得
205        // TODO: SC_CartSession::setPrevURL()利用不可。
206        $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
207        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
208
209        // すべてのカートの内容を取得する
210        $this->cartItems = $objCartSess->getAllCartList();
211
212
213    }
214
215    /**
216     * デストラクタ.
217     *
218     * @return void
219     */
220    function destroy()
221    {
222        parent::destroy();
223    }
224
225    /**
226     * ユーザ入力値の処理
227     *
228     * @return object
229     */
230    function lfInitParam($arrRequest)
231    {
232        $objFormParam = new SC_FormParam_Ex();
233        $objFormParam->addParam('カートキー', 'cartKey', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
234        $objFormParam->addParam('カートナンバー', 'cart_no', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
235        // スマートフォン版での数量変更用
236        $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
237        // 値の取得
238        $objFormParam->setParam($arrRequest);
239        // 入力値の変換
240        $objFormParam->convParam();
241
242        return $objFormParam;
243    }
244
245    /**
246     * PC版での開いているカテゴリーツリーの維持用の入力値
247     *
248     * @return object
249     */
250    function lfInitParam4OpenCategoryTree($arrRequest)
251    {
252        $objFormParam = new SC_FormParam_Ex();
253
254        $objFormParam->addParam('カテゴリID', 'category_id', INT_LEN, 'n',
255            array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
256        $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n',
257            array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
258
259        // 値の取得
260        $objFormParam->setParam($arrRequest);
261        // 入力値の変換
262        $objFormParam->convParam();
263
264        return $objFormParam;
265    }
266
267    /**
268     * order_temp_id の更新
269     *
270     * @return
271     */
272    function lfUpdateOrderTempid($pre_uniqid,$uniqid)
273    {
274        $sqlval['order_temp_id'] = $uniqid;
275        $where = 'order_temp_id = ?';
276        $objQuery =& SC_Query_Ex::getSingletonInstance();
277        $res = $objQuery->update('dtb_order_temp', $sqlval, $where, array($pre_uniqid));
278        if ($res != 1) {
279            return false;
280        }
281
282        return true;
283    }
284
285    /**
286     * 前頁のURLを取得
287     *
288     * @return void
289     */
290    function lfGetCartPrevUrl(&$session,$referer)
291    {
292        if (!preg_match('/cart/', $referer)) {
293            if (!empty($session['cart_referer_url'])) {
294                $session['cart_prev_url'] = $session['cart_referer_url'];
295                unset($session['cart_referer_url']);
296            } else {
297                if (preg_match('/entry/', $referer)) {
298                    $session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
299                } else {
300                    $session['cart_prev_url'] = $referer;
301                }
302            }
303        }
304        // 妥当性チェック
305        if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
306            $session['cart_prev_url'] = '';
307        }
308    }
309
310    /**
311     * カートを購入モードに設定
312     *
313     * @return void
314     */
315    function lfSetCurrentCart(&$objSiteSess, &$objCartSess, $cartKey)
316    {
317        // 正常に登録されたことを記録しておく
318        $objSiteSess->setRegistFlag();
319        $pre_uniqid = $objSiteSess->getUniqId();
320        // 注文一時IDの発行
321        $objSiteSess->setUniqId();
322        $uniqid = $objSiteSess->getUniqId();
323        // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
324        if ($pre_uniqid != '') {
325            $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
326        }
327        // カートを購入モードに設定
328        $objCartSess->registerKey($cartKey);
329        $objCartSess->saveCurrentCart($uniqid, $cartKey);
330    }
331}
Note: See TracBrowser for help on using the repository browser.