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

Revision 22807, 10.8 KB checked in by m_uehara, 11 years ago (diff)

#2171 ソース整形

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