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

Revision 18852, 10.5 KB checked in by nanasess, 13 years ago (diff)

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

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