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

Revision 18859, 10.1 KB checked in by nanasess, 14 years ago (diff)

ページ間の遷移方法の改善(#783)

  • カート内集計の関数が VIEW に依存しないように修正
  • SC_Helper_DB::sfTotalCart(), SC_Helper_DB::sfTotalConfirm() を SC_CartSession に移動
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2010 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_PATH . "pages/LC_Page.php");
26if (file_exists(MODULE_PATH . "mdl_gmopg/inc/function.php")) {
27    require_once(MODULE_PATH . "mdl_gmopg/inc/function.php");
28}
29
30/**
31 * カート のページクラス.
32 *
33 * @package Page
34 * @author LOCKON CO.,LTD.
35 * @version $Id:LC_Page_Cart.php 15532 2007-08-31 14:39:46Z nanasess $
36 */
37class LC_Page_Cart extends LC_Page {
38
39    // {{{ properties
40
41    /** セッションの配列 */
42    var $arrSession;
43
44    /** カテゴリの配列 */
45    var $arrProductsClass;
46
47    /** 商品規格情報の配列 */
48    var $arrData;
49
50    // }}}
51    // {{{ functions
52
53    /**
54     * Page を初期化する.
55     *
56     * @return void
57     */
58    function init() {
59        parent::init();
60        $this->tpl_mainpage = 'cart/index.tpl';
61        $this->tpl_column_num = 1;
62        $this->tpl_title = "現在のカゴの中";
63    }
64
65    /**
66     * Page のプロセス.
67     *
68     * @return void
69     */
70    function process() {
71
72        $objView = new SC_SiteView(false);
73        $objCartSess = new SC_CartSession();
74        $objSiteSess = new SC_SiteSession();
75        $objCampaignSess = new SC_CampaignSession();
76        $objSiteInfo = $objView->objSiteInfo;
77        $objCustomer = new SC_Customer();
78        $objDb = new SC_Helper_DB_Ex();
79        $objProduct = new SC_Product();
80
81        $i = 0;
82        $this->cartKeys = $objCartSess->getKeys();
83        foreach ($this->cartKeys as $key) {
84            // 商品購入中にカート内容が変更された。
85            if($objCartSess->getCancelPurchase($key)) {
86                $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。";
87            }
88        }
89        $this->cartItems =& $objCartSess->getAllCartList();
90
91        if (!isset($_POST['mode'])) $_POST['mode'] = "";
92
93        switch($_POST['mode']) {
94        case 'up':
95            $objCartSess->upQuantity($_POST['cart_no'], $_POST['cartKey']);
96            $this->reload(); // PRG pattern
97            break;
98        case 'down':
99            $objCartSess->downQuantity($_POST['cart_no'], $_POST['cartKey']);
100            $this->reload(); // PRG pattern
101            break;
102        case 'delete':
103            $objCartSess->delProduct($_POST['cart_no'], $_POST['cartKey']);
104            $this->reload(); // PRG pattern
105            break;
106        case 'confirm':
107            // カート内情報の取得
108            $cartKey = $_POST['cartKey'];
109            $cartList = $objCartSess->getCartList($cartKey);
110            // カート商品が1件以上存在する場合
111            if(count($cartList) > 0) {
112                // 正常に登録されたことを記録しておく
113                $objSiteSess->setRegistFlag();
114                $pre_uniqid = $objSiteSess->getUniqId();
115                // 注文一時IDの発行
116                $objSiteSess->setUniqId();
117                $uniqid = $objSiteSess->getUniqId();
118                // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
119                if($pre_uniqid != "") {
120                    $sqlval['order_temp_id'] = $uniqid;
121                    $where = "order_temp_id = ?";
122                    $objQuery = new SC_Query();
123                    $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid));
124                }
125                // カートを購入モードに設定
126                $objCartSess->saveCurrentCart($uniqid, $cartKey);
127                // 購入ページへ
128                $this->sendRedirect(URL_SHOP_TOP);
129                exit;
130            }
131            break;
132        default:
133            break;
134        }
135
136        // 基本情報の取得
137        $this->arrInfo = $objSiteInfo->data;
138        foreach ($this->cartKeys as $key) {
139            // カート集計処理
140            $this->tpl_message = $objCartSess->checkProducts($key);
141            $this->tpl_total_pretax[$key] = $objCartSess->getAllProductsTotal($key);
142            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
143            // ポイント合計
144            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
145            $this->arrData = $objCartSess->calculate($key, $objCustomer);
146
147            // 送料無料までの金額を計算
148            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_pretax[$key];
149        }
150
151        // ログイン判定
152        if($objCustomer->isLoginSuccess()) {
153            $this->tpl_login = true;
154            $this->tpl_user_point = $objCustomer->getValue('point');
155            $this->tpl_name = $objCustomer->getValue('name01');
156        }
157
158        // 前頁のURLを取得
159        $this->tpl_prev_url = $objCartSess->getPrevURL();
160
161        $objView->assignobj($this);
162        // フレームを選択(キャンペーンページから遷移なら変更)
163        $objCampaignSess->pageView($objView);
164    }
165
166    /**
167     * モバイルページを初期化する.
168     *
169     * @return void
170     */
171    function mobileInit() {
172        $this->init();
173    }
174
175    /**
176     * Page のプロセス(モバイル).
177     *
178     * @return void
179     */
180    function mobileProcess() {
181
182        // 買い物を続ける場合
183        if ($_REQUEST['mode'] == 'continue') {
184            $this->sendRedirect($this->getLocation(MOBILE_URL_SITE_TOP), true);
185            exit;
186        }
187
188        $objView = new SC_MobileView(false);
189        $objCartSess = new SC_CartSession();
190        $objSiteSess = new SC_SiteSession();
191        $objSiteInfo = $objView->objSiteInfo;
192        $objCustomer = new SC_Customer();
193        $objDb = new SC_Helper_DB_Ex();
194
195        // 商品購入中にカート内容が変更された。
196        if($objCartSess->getCancelPurchase()) {
197            $this->tpl_message = "商品購入中にカート内容が変更されましたので、お手数ですが購入手続きをやり直して下さい。";
198        }
199
200        switch($_POST['mode']) {
201        case 'confirm':
202            // カート内情報の取得
203            $arrRet = $objCartSess->getCartList();
204            $max = count($arrRet);
205            $cnt = 0;
206            for ($i = 0; $i < $max; $i++) {
207                // 商品規格情報の取得
208                $arrData = $objDb->sfGetProductsClass($arrRet[$i]['id']);
209                // DBに存在する商品
210                if($arrData != "") {
211                    $cnt++;
212                }
213            }
214            // カート商品が1件以上存在する場合
215            if($cnt > 0) {
216                // 正常に登録されたことを記録しておく
217                $objSiteSess->setRegistFlag();
218                $pre_uniqid = $objSiteSess->getUniqId();
219                // 注文一時IDの発行
220                $objSiteSess->setUniqId();
221                $uniqid = $objSiteSess->getUniqId();
222                // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
223                if($pre_uniqid != "") {
224                    $sqlval['order_temp_id'] = $uniqid;
225                    $where = "order_temp_id = ?";
226                    $objQuery = new SC_Query();
227                    $objQuery->update("dtb_order_temp", $sqlval, $where, array($pre_uniqid));
228                }
229                // カートを購入モードに設定
230                $objCartSess->saveCurrentCart($uniqid);
231                // 購入ページへ
232                $this->sendRedirect(MOBILE_URL_SHOP_TOP, true);
233                exit;
234            }
235            break;
236        default:
237            break;
238        }
239
240        if (!isset($_GET['mode'])) $_GET['mode'] = "";
241
242        /*
243         * FIXME sendRedirect() を使った方が良いが無限ループしてしまう...
244         */
245        switch($_GET['mode']) {
246        case 'up':
247            $objCartSess->upQuantity($_GET['cart_no']);
248            SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
249            break;
250        case 'down':
251            $objCartSess->downQuantity($_GET['cart_no']);
252            SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
253            break;
254        case 'delete':
255            $objCartSess->delProduct($_GET['cart_no']);
256            SC_Utils_Ex::sfReload(session_name() . "=" . session_id());
257            break;
258        }
259
260        // カート集計処理
261        if (empty($arrData)) {
262            $arrData = array();
263        }
264        $objDb->sfTotalCart($this, $objCartSess);
265        $this->arrData = $objDb->sfTotalConfirm($arrData, $this, $objCartSess, null, $objCustomer);
266
267        // 基本情報の取得
268        $this->arrInfo = $objSiteInfo->data;
269
270        // ログイン判定
271        if($objCustomer->isLoginSuccess(true)) {
272            $this->tpl_login = true;
273            $this->tpl_user_point = $objCustomer->getValue('point');
274            $this->tpl_name = $objCustomer->getValue('name01');
275        }
276
277        // 送料無料までの金額を計算
278        $tpl_deliv_free = $this->arrInfo['free_rule'] - $this->tpl_total_pretax;
279        $this->tpl_deliv_free = $tpl_deliv_free;
280
281        // 前頁のURLを取得
282        $this->tpl_prev_url = $objCartSess->getPrevURL();
283
284        $objView->assignobj($this);
285        $objView->display(SITE_FRAME);
286    }
287
288    /**
289     * デストラクタ.
290     *
291     * @return void
292     */
293    function destroy() {
294        parent::destroy();
295    }
296}
297?>
Note: See TracBrowser for help on using the repository browser.