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

Revision 23027, 10.7 KB checked in by yomoro, 11 years ago (diff)

#1506 決済処理中でストップした際に在庫とポイントが差し引かれてしまう 対応。一旦こちらの形でコミットさせていただきます。

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