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