source: branches/version-2_12_4en/data/class/pages/cart/LC_Page_Cart.php @ 22800

Revision 22800, 9.4 KB checked in by michael_nelson, 11 years ago (diff)

#2238 Merged r22580, r22604 and r22798

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2012 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_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
26
27/**
28 * カート のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Cart extends LC_Page_Ex {
35
36    // {{{ properties
37
38    /** 商品規格情報の配列 */
39    var $arrData;
40
41    /** 動作モード */
42    var $mode;
43
44    /** メッセージ */
45    public $tpl_message = '';
46
47    // }}}
48    // {{{ functions
49
50    /**
51     * Page を初期化する.
52     *
53     * @return void
54     */
55    function init() {
56        parent::init();
57        $this->tpl_title = t('c_Items in cart_01');
58        $masterData = new SC_DB_MasterData_Ex();
59        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
60
61    }
62
63    /**
64     * Page のプロセス.
65     *
66     * @return void
67     */
68    function process() {
69        parent::process();
70        $this->action();
71        $this->sendResponse();
72    }
73
74    /**
75     * Page のアクション.
76     *
77     * @return void
78     */
79    function action() {
80
81        $objCartSess = new SC_CartSession_Ex();
82        $objSiteSess = new SC_SiteSession_Ex();
83        $objCustomer = new SC_Customer_Ex();
84
85        $objFormParam = $this->lfInitParam($_POST);
86        $this->mode = $this->getMode();
87
88        $this->cartKeys = $objCartSess->getKeys();
89        foreach ($this->cartKeys as $key) {
90            // 商品購入中にカート内容が変更された。
91            if ($objCartSess->getCancelPurchase($key)) {
92                $this->tpl_message .= t('c_The contents of your cart were modified during product purchase. Please restart the purchasing procedure._01');
93            }
94        }
95
96        $cart_no = $objFormParam->getValue('cart_no');
97        $cartKey = $objFormParam->getValue('cartKey');
98       
99        // エラーチェック
100        $arrError = $objFormParam->checkError();
101        if(isset($arrError) && !empty($arrError)) {
102            SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND);
103            SC_Response_Ex::actionExit();
104        }
105
106        switch ($this->mode) {
107            case 'confirm':
108                // カート内情報の取得
109                $cartList = $objCartSess->getCartList($cartKey);
110                // カート商品が1件以上存在する場合
111                if (count($cartList) > 0) {
112                    // カートを購入モードに設定
113                    $this->lfSetCurrentCart($objSiteSess, $objCartSess, $cartKey);
114
115
116                    // 購入ページへ
117                    SC_Response_Ex::sendRedirect(SHOPPING_URL);
118                    SC_Response_Ex::actionExit();
119                }
120                break;
121            case 'up'://1個追加
122                $objCartSess->upQuantity($cart_no, $cartKey);
123
124
125                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
126                SC_Response_Ex::actionExit();
127                break;
128            case 'down'://1個減らす
129                $objCartSess->downQuantity($cart_no, $cartKey);
130
131
132                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
133                SC_Response_Ex::actionExit();
134                break;
135            case 'setQuantity'://数量変更
136                $objCartSess->setQuantity($objFormParam->getValue('quantity'), $cart_no, $cartKey);
137
138
139                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
140                SC_Response_Ex::actionExit();
141                break;
142            case 'delete'://カートから削除
143                $objCartSess->delProduct($cart_no, $cartKey);
144
145
146                SC_Response_Ex::reload(array('category_id' => $objFormParam->getValue('category_id')), true);
147                SC_Response_Ex::actionExit();
148                break;
149            default:
150                break;
151        }
152        $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData();
153        $totalIncTax = 0;
154        foreach ($this->cartKeys as $key) {
155            // カート集計処理
156            $this->tpl_message .= $objCartSess->checkProducts($key);
157            $this->tpl_total_inctax[$key] = $objCartSess->getAllProductsTotal($key);
158            $totalIncTax += $this->tpl_total_inctax[$key];
159            $this->tpl_total_tax[$key] = $objCartSess->getAllProductsTax($key);
160            // ポイント合計
161            $this->tpl_total_point[$key] = $objCartSess->getAllProductsPoint($key);
162
163            $this->arrData[$key] = $objCartSess->calculate($key, $objCustomer);
164
165            // 送料無料チェック
166            $this->arrData[$key]['is_deliv_free'] = $objCartSess->isDelivFree($key);
167
168            // 送料無料までの金額を計算
169            $this->tpl_deliv_free[$key] = $this->arrInfo['free_rule'] - $this->tpl_total_inctax[$key];
170        }
171
172        //商品の合計金額をセット
173        $this->tpl_all_total_inctax = $totalIncTax;
174
175        $this->tpl_category_id = $objFormParam->getValue('category_id');
176
177        // ログイン判定
178        if ($objCustomer->isLoginSuccess(true)) {
179            $this->tpl_login = true;
180            $this->tpl_user_point = $objCustomer->getValue('point');
181            $this->tpl_name = $objCustomer->getValue('name01');
182        }
183
184        // 前頁のURLを取得
185        // TODO: SC_CartSession::setPrevURL()利用不可。
186        $this->lfGetCartPrevUrl($_SESSION,$_SERVER['HTTP_REFERER']);
187        $this->tpl_prev_url = (isset($_SESSION['cart_prev_url'])) ? $_SESSION['cart_prev_url'] : '';
188
189        // すべてのカートの内容を取得する
190        $this->cartItems = $objCartSess->getAllCartList();
191
192
193    }
194
195    /**
196     * デストラクタ.
197     *
198     * @return void
199     */
200    function destroy() {
201        parent::destroy();
202    }
203
204    /**
205     * ユーザ入力値の処理
206     *
207     * @return object
208     */
209    function lfInitParam($arrRequest) {
210        $objFormParam = new SC_FormParam_Ex();
211        $objFormParam->addParam(t('c_Cart key_01'), 'cartKey', INT_LEN, 'n', array('NUM_CHECK','MAX_LENGTH_CHECK'));
212        $objFormParam->addParam(t('c_Cart number_01'), 'cart_no', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
213        // PC版での値引き継ぎ用
214        $objFormParam->addParam(t('c_Category ID_01'), 'category_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
215        // スマートフォン版での数量変更用
216        $objFormParam->addParam(t('c_Quantity_01'), 'quantity', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
217        // 値の取得
218        $objFormParam->setParam($arrRequest);
219        // 入力値の変換
220        $objFormParam->convParam();
221        return $objFormParam;
222    }
223
224    /**
225     * order_temp_id の更新
226     *
227     * @return
228     */
229    function lfUpdateOrderTempid($pre_uniqid,$uniqid) {
230        $sqlval['order_temp_id'] = $uniqid;
231        $where = 'order_temp_id = ?';
232        $objQuery =& SC_Query_Ex::getSingletonInstance();
233        $res = $objQuery->update('dtb_order_temp', $sqlval, $where, array($pre_uniqid));
234        if ($res != 1) {
235            return false;
236        }
237        return true;
238    }
239
240    /**
241     * 前頁のURLを取得
242     *
243     * @return void
244     */
245    function lfGetCartPrevUrl(&$session,$referer) {
246        if (!preg_match('/cart/', $referer)) {
247            if (!empty($session['cart_referer_url'])) {
248                $session['cart_prev_url'] = $session['cart_referer_url'];
249                unset($session['cart_referer_url']);
250            } else {
251                if (preg_match('/entry/', $referer)) {
252                    $session['cart_prev_url'] = HTTPS_URL . 'entry/kiyaku.php';
253                } else {
254                    $session['cart_prev_url'] = $referer;
255                }
256            }
257        }
258        // 妥当性チェック
259        if (!SC_Utils_Ex::sfIsInternalDomain($session['cart_prev_url'])) {
260            $session['cart_prev_url'] = '';
261        }
262    }
263
264    /**
265     * カートを購入モードに設定
266     *
267     * @return void
268     */
269    function lfSetCurrentCart(&$objSiteSess, &$objCartSess, $cartKey) {
270        // 正常に登録されたことを記録しておく
271        $objSiteSess->setRegistFlag();
272        $pre_uniqid = $objSiteSess->getUniqId();
273        // 注文一時IDの発行
274        $objSiteSess->setUniqId();
275        $uniqid = $objSiteSess->getUniqId();
276        // エラーリトライなどで既にuniqidが存在する場合は、設定を引き継ぐ
277        if ($pre_uniqid != '') {
278            $this->lfUpdateOrderTempid($pre_uniqid,$uniqid);
279        }
280        // カートを購入モードに設定
281        $objCartSess->registerKey($cartKey);
282        $objCartSess->saveCurrentCart($uniqid, $cartKey);
283    }
284}
Note: See TracBrowser for help on using the repository browser.