source: branches/version-2_13_0/data/class/pages/cart/LC_Page_Cart.php @ 23126

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

#2348 r23116 - r23125 をマージ

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