source: branches/version-2_12_4en/data/class/pages/cart/LC_Page_Cart.php @ 22816

Revision 22816, 9.7 KB checked in by michael_nelson, 11 years ago (diff)

#2238 mobileの部分を対応しました。

  • 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 = t('c_Items in cart_01');
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($_POST);
86        $this->mode = $this->getMode();
87
88        // モバイル対応
89        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) {
90            if (isset($_GET['cart_no'])) {
91                $objFormParam->setValue('cart_no', $_GET['cart_no']);
92            }
93            if (isset($_GET['cartKey'])) {
94                    $objFormParam->setValue('cartKey', $_GET['cartKey']);
95            }
96        }
97       
98        $this->cartKeys = $objCartSess->getKeys();
99        foreach ($this->cartKeys as $key) {
100            // 商品購入中にカート内容が変更された。
101            if ($objCartSess->getCancelPurchase($key)) {
102                $this->tpl_message .= t('c_The contents of your cart were modified during product purchase. Please restart the purchasing procedure._01');
103            }
104        }
105
106        $cart_no = $objFormParam->getValue('cart_no');
107        $cartKey = $objFormParam->getValue('cartKey');
108       
109        // エラーチェック
110        $arrError = $objFormParam->checkError();
111        if(isset($arrError) && !empty($arrError)) {
112            SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND);
113            SC_Response_Ex::actionExit();
114        }
115
116        switch ($this->mode) {
117            case 'confirm':
118                // カート内情報の取得
119                $cartList = $objCartSess->getCartList($cartKey);
120                // カート商品が1件以上存在する場合
121                if (count($cartList) > 0) {
122                    // カートを購入モードに設定
123                    $this->lfSetCurrentCart($objSiteSess, $objCartSess, $cartKey);
124
125
126                    // 購入ページへ
127                    SC_Response_Ex::sendRedirect(SHOPPING_URL);
128                    SC_Response_Ex::actionExit();
129                }
130                break;
131            case 'up'://1個追加
132                $objCartSess->upQuantity($cart_no, $cartKey);
133
134
135                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
136                SC_Response_Ex::actionExit();
137                break;
138            case 'down'://1個減らす
139                $objCartSess->downQuantity($cart_no, $cartKey);
140
141
142                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
143                SC_Response_Ex::actionExit();
144                break;
145            case 'setQuantity'://数量変更
146                $objCartSess->setQuantity($objFormParam->getValue('quantity'), $cart_no, $cartKey);
147
148
149                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
150                SC_Response_Ex::actionExit();
151                break;
152            case 'delete'://カートから削除
153                $objCartSess->delProduct($cart_no, $cartKey);
154
155
156                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
157                SC_Response_Ex::actionExit();
158                break;
159            default:
160                break;
161        }
162        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
163        $totalIncTax = 0;
164        foreach ($this->cartKeys as $key) {
165            // カート集計処理
166            $this->tpl_message .= $objCartSess->checkProducts($key);
167            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
168            $totalIncTax += $this->tpl_total_inctax[$key];
169            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
170            // ポイント合計
171            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
172
173            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
174
175            // 送料無料チェック
176            $this->arrData[$key]['is_deliv_free'] = $objCartSess->isDelivFree($key);
177
178            // 送料無料までの金額を計算
179            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
180        }
181
182        //商品の合計金額をセット
183        $this->tpl_all_total_inctax = $totalIncTax;
184
185        $this->tpl_category_id = $objFormParam->getValue('category_id');
186
187        // ログイン判定
188        if ($objCustomer->isLoginSuccess(true)) {
189            $this->tpl_login = true;
190            $this->tpl_user_point = $objCustomer->getValue('point');
191            $this->tpl_name = $objCustomer->getValue('name01');
192        }
193
194        // 前頁のURLを取得
195        // TODO: SC_CartSession::setPrevURL()利用不可。
196        $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
197        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
198
199        // すべてのカートの内容を取得する
200        $this->cartItems = $objCartSess->getAllCartList();
201
202
203    }
204
205    /**
206     * デストラクタ.
207     *
208     * @return void
209     */
210    function destroy() {
211        parent::destroy();
212    }
213
214    /**
215     * ユーザ入力値の処理
216     *
217     * @return object
218     */
219    function lfInitParam($arrRequest) {
220        $objFormParam = new SC_FormParam_Ex();
221        $objFormParam->addParam(t('c_Cart key_01'), 'cartKey', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
222        $objFormParam->addParam(t('c_Cart number_01'), 'cart_no', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
223        // PC版での値引き継ぎ用
224        $objFormParam->addParam(t('c_Category ID_01'), 'category_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
225        // スマートフォン版での数量変更用
226        $objFormParam->addParam(t('c_Quantity_01'), 'quantity', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
227        // 値の取得
228        $objFormParam->setParam($arrRequest);
229        // 入力値の変換
230        $objFormParam->convParam();
231        return $objFormParam;
232    }
233
234    /**
235     * order_temp_id の更新
236     *
237     * @return
238     */
239    function lfUpdateOrderTempid($pre_uniqid,$uniqid) {
240        $sqlval['order_temp_id'] = $uniqid;
241        $where = 'order_temp_id = ?';
242        $objQuery =& SC_Query_Ex::getSingletonInstance();
243        $res = $objQuery->update('dtb_order_temp', $sqlval, $where, array($pre_uniqid));
244        if ($res != 1) {
245            return false;
246        }
247        return true;
248    }
249
250    /**
251     * 前頁のURLを取得
252     *
253     * @return void
254     */
255    function lfGetCartPrevUrl(&$session,$referer) {
256        if (!preg_match('/cart/', $referer)) {
257            if (!empty($session['cart_referer_url'])) {
258                $session['cart_prev_url'] = $session['cart_referer_url'];
259                unset($session['cart_referer_url']);
260            } else {
261                if (preg_match('/entry/', $referer)) {
262                    $session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
263                } else {
264                    $session['cart_prev_url'] = $referer;
265                }
266            }
267        }
268        // 妥当性チェック
269        if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
270            $session['cart_prev_url'] = '';
271        }
272    }
273
274    /**
275     * カートを購入モードに設定
276     *
277     * @return void
278     */
279    function lfSetCurrentCart(&$objSiteSess, &$objCartSess, $cartKey) {
280        // 正常に登録されたことを記録しておく
281        $objSiteSess->setRegistFlag();
282        $pre_uniqid = $objSiteSess->getUniqId();
283        // 注文一時IDの発行
284        $objSiteSess->setUniqId();
285        $uniqid = $objSiteSess->getUniqId();
286        // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
287        if ($pre_uniqid != '') {
288            $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
289        }
290        // カートを購入モードに設定
291        $objCartSess->registerKey($cartKey);
292        $objCartSess->saveCurrentCart($uniqid, $cartKey);
293    }
294}
Note: See TracBrowser for help on using the repository browser.