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