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

Revision 19815, 10.3 KB checked in by nanasess, 13 years ago (diff)

#823(商品種別によってカートを分ける)

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