source: branches/comu-ver2/data/class/pages/cart/LC_Page_Cart.php @ 17675

Revision 17675, 9.9 KB checked in by Seasoft, 15 years ago (diff)

merge 17653

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