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