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

Revision 18830, 10.0 KB checked in by nanasess, 14 years ago (diff)

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

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