1 | <?php |
---|
2 | /* |
---|
3 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
4 | * |
---|
5 | * http://www.lockon.co.jp/ |
---|
6 | */ |
---|
7 | |
---|
8 | // {{{ requires |
---|
9 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
10 | |
---|
11 | /** |
---|
12 | * 商品一覧 のページクラス. |
---|
13 | * |
---|
14 | * @package Page |
---|
15 | * @author LOCKON CO.,LTD. |
---|
16 | * @version $Id$ |
---|
17 | */ |
---|
18 | class LC_Page_Products_List extends LC_Page { |
---|
19 | |
---|
20 | // {{{ properties |
---|
21 | |
---|
22 | // TODO |
---|
23 | var $arrSTATUS = array(); |
---|
24 | var $arrSTATUS_IMAGE = array(); |
---|
25 | var $arrDELIVERYDATE = array(); |
---|
26 | var $arrPRODUCTLISTMAX = array(); |
---|
27 | |
---|
28 | // }}} |
---|
29 | // {{{ functions |
---|
30 | |
---|
31 | /** |
---|
32 | * Page を初期化する. |
---|
33 | * |
---|
34 | * @return void |
---|
35 | */ |
---|
36 | function init() { |
---|
37 | parent::init(); |
---|
38 | session_cache_limiter('private-no-expire'); |
---|
39 | $this->arrPRODUCTLISTMAX = array(15 => '15件', |
---|
40 | 30 => '30件', |
---|
41 | 50 => '50件'); |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * Page のプロセス. |
---|
46 | * |
---|
47 | * @return void |
---|
48 | */ |
---|
49 | function process() { |
---|
50 | $conn = new SC_DBConn(); |
---|
51 | |
---|
52 | //表示件数の選択 |
---|
53 | if(SC_Utils_Ex::sfIsInt($_POST['disp_number'])) { |
---|
54 | $this->disp_number = $_POST['disp_number']; |
---|
55 | } else { |
---|
56 | //最小表示件数を選択 |
---|
57 | $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX)); |
---|
58 | } |
---|
59 | |
---|
60 | //表示順序の保存 |
---|
61 | $this->orderby = $_POST['orderby']; |
---|
62 | |
---|
63 | // GETのカテゴリIDを元に正しいカテゴリIDを取得する。 |
---|
64 | $category_id = SC_Utils_Ex::sfGetCategoryId("", $_GET['category_id']); |
---|
65 | |
---|
66 | // タイトル編集 |
---|
67 | $tpl_subtitle = ""; |
---|
68 | if($_GET['mode'] == 'search'){ |
---|
69 | $tpl_subtitle = "検索結果"; |
---|
70 | }elseif ($category_id == "" ) { |
---|
71 | $tpl_subtitle = "全商品"; |
---|
72 | }else{ |
---|
73 | $arrFirstCat = SC_Utils_Ex::sfGetFirstCat($category_id); |
---|
74 | $tpl_subtitle = $arrFirstCat['name']; |
---|
75 | } |
---|
76 | |
---|
77 | $objQuery = new SC_Query(); |
---|
78 | $count = $objQuery->count("dtb_best_products", "category_id = ?", array($category_id)); |
---|
79 | |
---|
80 | // 以下の条件でBEST商品を表示する |
---|
81 | // ・BEST最大数の商品が登録されている。 |
---|
82 | // ・カテゴリIDがルートIDである。 |
---|
83 | // ・検索モードでない。 |
---|
84 | if(($count >= BEST_MIN) && lfIsRootCategory($category_id) && ($_GET['mode'] != 'search') ) { |
---|
85 | // 商品TOPの表示処理 |
---|
86 | /** 必ず指定する **/ |
---|
87 | $this->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl"; // メインテンプレート |
---|
88 | |
---|
89 | $this->arrBestItems = sfGetBestProducts($conn, $category_id); |
---|
90 | $this->BEST_ROOP_MAX = ceil((BEST_MAX-1)/2); |
---|
91 | } else { |
---|
92 | if ($_GET['mode'] == 'search' && strlen($_GET['category_id']) == 0 ){ |
---|
93 | // 検索時にcategory_idがGETに存在しない場合は、仮に埋めたIDを空白に戻す |
---|
94 | $category_id = ''; |
---|
95 | } |
---|
96 | |
---|
97 | // 商品一覧の表示処理 |
---|
98 | $this = $this->lfDispProductsList($category_id, $_GET['name'], $this->disp_number, $_POST['orderby']); |
---|
99 | |
---|
100 | // 検索条件を画面に表示 |
---|
101 | // カテゴリー検索条件 |
---|
102 | if (strlen($_GET['category_id']) == 0) { |
---|
103 | $arrSearch['category'] = "指定なし"; |
---|
104 | }else{ |
---|
105 | $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id)); |
---|
106 | $arrSearch['category'] = $arrCat; |
---|
107 | } |
---|
108 | |
---|
109 | // 商品名検索条件 |
---|
110 | if ($_GET['name'] === "") { |
---|
111 | $arrSearch['name'] = "指定なし"; |
---|
112 | }else{ |
---|
113 | $arrSearch['name'] = $_GET['name']; |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | // レイアウトデザインを取得 |
---|
118 | $layout = new SC_Helper_PageLayout_Ex(); |
---|
119 | $this = $layout->sfGetPageLayout($this, false, "products/list.php"); |
---|
120 | |
---|
121 | if($_POST['mode'] == "cart" && $_POST['product_id'] != "") { |
---|
122 | // 値の正当性チェック |
---|
123 | if(!sfIsInt($_POST['product_id']) || !sfIsRecord("dtb_products", "product_id", $_POST['product_id'], "del_flg = 0 AND status = 1")) { |
---|
124 | sfDispSiteError(PRODUCT_NOT_FOUND); |
---|
125 | } else { |
---|
126 | // 入力値の変換 |
---|
127 | $this->arrErr = lfCheckError($_POST['product_id']); |
---|
128 | if(count($this->arrErr) == 0) { |
---|
129 | $objCartSess = new SC_CartSession(); |
---|
130 | $classcategory_id = "classcategory_id". $_POST['product_id']; |
---|
131 | $classcategory_id1 = $_POST[$classcategory_id. '_1']; |
---|
132 | $classcategory_id2 = $_POST[$classcategory_id. '_2']; |
---|
133 | $quantity = "quantity". $_POST['product_id']; |
---|
134 | // 規格1が設定されていない場合 |
---|
135 | if(!$this->tpl_classcat_find1[$_POST['product_id']]) { |
---|
136 | $classcategory_id1 = '0'; |
---|
137 | } |
---|
138 | // 規格2が設定されていない場合 |
---|
139 | if(!$this->tpl_classcat_find2[$_POST['product_id']]) { |
---|
140 | $classcategory_id2 = '0'; |
---|
141 | } |
---|
142 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
---|
143 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]); |
---|
144 | header("Location: " . URL_CART_TOP); |
---|
145 | exit; |
---|
146 | } |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | $this->tpl_subtitle = $tpl_subtitle; |
---|
152 | |
---|
153 | // 支払方法の取得 |
---|
154 | $this->arrPayment = $this->lfGetPayment(); |
---|
155 | // 入力情報を渡す |
---|
156 | $this->arrForm = $_POST; |
---|
157 | |
---|
158 | $this->lfConvertParam(); |
---|
159 | |
---|
160 | $this->category_id = $category_id; |
---|
161 | $this->arrSearch = $arrSearch; |
---|
162 | |
---|
163 | SC_Utils_Ex::sfCustomDisplay($this); |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * デストラクタ. |
---|
168 | * |
---|
169 | * @return void |
---|
170 | */ |
---|
171 | function destroy() { |
---|
172 | parent::destroy(); |
---|
173 | } |
---|
174 | |
---|
175 | /* カテゴリIDがルートかどうかの判定 */ |
---|
176 | function lfIsRootCategory($category_id) { |
---|
177 | $objQuery = new SC_Query(); |
---|
178 | $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id)); |
---|
179 | if($level == 1) { |
---|
180 | return true; |
---|
181 | } |
---|
182 | return false; |
---|
183 | } |
---|
184 | |
---|
185 | /* 商品一覧の表示 */ |
---|
186 | function lfDispProductsList($category_id, $name, $disp_num, $orderby) { |
---|
187 | global $objPage; |
---|
188 | $objQuery = new SC_Query(); |
---|
189 | $objPage->tpl_pageno = $_POST['pageno']; |
---|
190 | |
---|
191 | //表示件数でテンプレートを切り替える |
---|
192 | $objPage->tpl_mainpage = HTML_PATH . "user_data/templates/list.tpl"; // メインテンプレート |
---|
193 | |
---|
194 | //表示順序 |
---|
195 | switch($orderby) { |
---|
196 | //価格順 |
---|
197 | case 'price': |
---|
198 | $order = "price02_min ASC"; |
---|
199 | break; |
---|
200 | //新着順 |
---|
201 | case 'date': |
---|
202 | $order = "create_date DESC"; |
---|
203 | break; |
---|
204 | default: |
---|
205 | $order = "category_rank DESC, rank DESC"; |
---|
206 | break; |
---|
207 | } |
---|
208 | |
---|
209 | // 商品検索条件の作成(未削除、表示) |
---|
210 | $where = "del_flg = 0 AND status = 1 "; |
---|
211 | // カテゴリからのWHERE文字列取得 |
---|
212 | if ( $category_id ) { |
---|
213 | list($tmp_where, $arrval) = SC_Utils_Ex::sfGetCatWhere($category_id); |
---|
214 | if($tmp_where != "") { |
---|
215 | $where.= " AND $tmp_where"; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | // 商品名をwhere文に |
---|
220 | $name = ereg_replace(",", "", $name); |
---|
221 | if ( strlen($name) > 0 ){ |
---|
222 | $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) "; |
---|
223 | $ret = sfManualEscape($name); |
---|
224 | $arrval[] = "%$ret%"; |
---|
225 | $arrval[] = "%$ret%"; |
---|
226 | } |
---|
227 | |
---|
228 | // 行数の取得 |
---|
229 | $linemax = $objQuery->count("vw_products_allclass AS allcls", $where, $arrval); |
---|
230 | $objPage->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
231 | |
---|
232 | // ページ送りの取得 |
---|
233 | $objNavi = new SC_PageNavi($_POST['pageno'], $linemax, $disp_num, "fnNaviPage", NAVI_PMAX); |
---|
234 | |
---|
235 | $strnavi = $objNavi->strnavi; |
---|
236 | $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi); |
---|
237 | $objPage->tpl_strnavi = $strnavi; // 表示文字列 |
---|
238 | $startno = $objNavi->start_row; // 開始行 |
---|
239 | |
---|
240 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
241 | $objQuery->setlimitoffset($disp_num, $startno); |
---|
242 | // 表示順序 |
---|
243 | $objQuery->setorder($order); |
---|
244 | |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | // 検索結果の取得 |
---|
253 | $objPage->arrProducts = $objQuery->select("*", "vw_products_allclass AS allcls", $where, $arrval); |
---|
254 | |
---|
255 | // 規格名一覧 |
---|
256 | $arrClassName = SC_Utils_Ex::sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
257 | // 規格分類名一覧 |
---|
258 | $arrClassCatName = SC_Utils_Ex::sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
259 | // 企画セレクトボックス設定 |
---|
260 | if($disp_num == 15) { |
---|
261 | for($i = 0; $i < count($objPage->arrProducts); $i++) { |
---|
262 | $objPage = $this->lfMakeSelect($objPage->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName); |
---|
263 | // 購入制限数を取得 |
---|
264 | $objPage = $this->lfGetSaleLimit($objPage->arrProducts[$i]); |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | return $objPage; |
---|
269 | } |
---|
270 | |
---|
271 | /* 規格セレクトボックスの作成 */ |
---|
272 | function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) { |
---|
273 | global $objPage; |
---|
274 | |
---|
275 | $classcat_find1 = false; |
---|
276 | $classcat_find2 = false; |
---|
277 | // 在庫ありの商品の有無 |
---|
278 | $stock_find = false; |
---|
279 | |
---|
280 | // 商品規格情報の取得 |
---|
281 | $arrProductsClass = $this->lfGetProductsClass($product_id); |
---|
282 | |
---|
283 | // 規格1クラス名の取得 |
---|
284 | $objPage->tpl_class_name1[$product_id] = $arrClassName[$arrProductsClass[0]['class_id1']]; |
---|
285 | // 規格2クラス名の取得 |
---|
286 | $objPage->tpl_class_name2[$product_id] = $arrClassName[$arrProductsClass[0]['class_id2']]; |
---|
287 | |
---|
288 | // すべての組み合わせ数 |
---|
289 | $count = count($arrProductsClass); |
---|
290 | |
---|
291 | $classcat_id1 = ""; |
---|
292 | |
---|
293 | $arrSele = array(); |
---|
294 | $arrList = array(); |
---|
295 | |
---|
296 | $list_id = 0; |
---|
297 | $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'"; |
---|
298 | $arrVal[0] = "\tval". $product_id. "_0 = new Array(''"; |
---|
299 | |
---|
300 | for ($i = 0; $i < $count; $i++) { |
---|
301 | // 在庫のチェック |
---|
302 | if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { |
---|
303 | continue; |
---|
304 | } |
---|
305 | |
---|
306 | $stock_find = true; |
---|
307 | |
---|
308 | // 規格1のセレクトボックス用 |
---|
309 | if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){ |
---|
310 | $arrList[$list_id].=");\n"; |
---|
311 | $arrVal[$list_id].=");\n"; |
---|
312 | $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; |
---|
313 | $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1]; |
---|
314 | $list_id++; |
---|
315 | } |
---|
316 | |
---|
317 | // 規格2のセレクトボックス用 |
---|
318 | $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; |
---|
319 | |
---|
320 | // セレクトボックス表示値 |
---|
321 | if($arrList[$list_id] == "") { |
---|
322 | $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'"; |
---|
323 | } else { |
---|
324 | $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'"; |
---|
325 | } |
---|
326 | |
---|
327 | // セレクトボックスPOST値 |
---|
328 | if($arrVal[$list_id] == "") { |
---|
329 | $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'"; |
---|
330 | } else { |
---|
331 | $arrVal[$list_id].= ", '".$classcat_id2."'"; |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | $arrList[$list_id].=");\n"; |
---|
336 | $arrVal[$list_id].=");\n"; |
---|
337 | |
---|
338 | // 規格1 |
---|
339 | $objPage->arrClassCat1[$product_id] = $arrSele; |
---|
340 | |
---|
341 | $lists = "\tlists".$product_id. " = new Array("; |
---|
342 | $no = 0; |
---|
343 | foreach($arrList as $val) { |
---|
344 | $objPage->tpl_javascript.= $val; |
---|
345 | if ($no != 0) { |
---|
346 | $lists.= ",list". $product_id. "_". $no; |
---|
347 | } else { |
---|
348 | $lists.= "list". $product_id. "_". $no; |
---|
349 | } |
---|
350 | $no++; |
---|
351 | } |
---|
352 | $objPage->tpl_javascript.= $lists.");\n"; |
---|
353 | |
---|
354 | $vals = "\tvals".$product_id. " = new Array("; |
---|
355 | $no = 0; |
---|
356 | foreach($arrVal as $val) { |
---|
357 | $objPage->tpl_javascript.= $val; |
---|
358 | if ($no != 0) { |
---|
359 | $vals.= ",val". $product_id. "_". $no; |
---|
360 | } else { |
---|
361 | $vals.= "val". $product_id. "_". $no; |
---|
362 | } |
---|
363 | $no++; |
---|
364 | } |
---|
365 | $objPage->tpl_javascript.= $vals.");\n"; |
---|
366 | |
---|
367 | // 選択されている規格2ID |
---|
368 | $classcategory_id = "classcategory_id". $product_id; |
---|
369 | $objPage->tpl_onload .= "lnSetSelect('".$classcategory_id."_1','".$classcategory_id."_2','".$product_id."','".$_POST[$classcategory_id."_2"]."'); "; |
---|
370 | |
---|
371 | // 規格1が設定されている |
---|
372 | if($arrProductsClass[0]['classcategory_id1'] != '0') { |
---|
373 | $classcat_find1 = true; |
---|
374 | } |
---|
375 | |
---|
376 | // 規格2が設定されている |
---|
377 | if($arrProductsClass[0]['classcategory_id2'] != '0') { |
---|
378 | $classcat_find2 = true; |
---|
379 | } |
---|
380 | |
---|
381 | $objPage->tpl_classcat_find1[$product_id] = $classcat_find1; |
---|
382 | $objPage->tpl_classcat_find2[$product_id] = $classcat_find2; |
---|
383 | $objPage->tpl_stock_find[$product_id] = $stock_find; |
---|
384 | |
---|
385 | return $objPage; |
---|
386 | } |
---|
387 | /* 商品規格情報の取得 */ |
---|
388 | function lfGetProductsClass($product_id) { |
---|
389 | $arrRet = array(); |
---|
390 | if(SC_Utils_Ex::sfIsInt($product_id)) { |
---|
391 | // 商品規格取得 |
---|
392 | $objQuery = new SC_Query(); |
---|
393 | $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited"; |
---|
394 | $table = "vw_product_class AS prdcls"; |
---|
395 | $where = "product_id = ?"; |
---|
396 | $objQuery->setorder("rank1 DESC, rank2 DESC"); |
---|
397 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
398 | } |
---|
399 | return $arrRet; |
---|
400 | } |
---|
401 | |
---|
402 | /* 入力内容のチェック */ |
---|
403 | function lfCheckError($id) { |
---|
404 | global $objPage; |
---|
405 | |
---|
406 | // 入力データを渡す。 |
---|
407 | $objErr = new SC_CheckError(); |
---|
408 | |
---|
409 | $classcategory_id1 = "classcategory_id". $id. "_1"; |
---|
410 | $classcategory_id2 = "classcategory_id". $id. "_2"; |
---|
411 | $quantity = "quantity". $id; |
---|
412 | // 複数項目チェック |
---|
413 | if ($objPage->tpl_classcat_find1[$id]) { |
---|
414 | $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
415 | } |
---|
416 | if ($objPage->tpl_classcat_find2[$id]) { |
---|
417 | $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
418 | } |
---|
419 | $objErr->doFunc(array("個数", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
420 | |
---|
421 | return $objErr->arrErr; |
---|
422 | } |
---|
423 | |
---|
424 | // 購入制限数の設定 |
---|
425 | function lfGetSaleLimit($product) { |
---|
426 | global $objPage; |
---|
427 | //在庫が無限または購入制限値が設定値より大きい場合 |
---|
428 | if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) { |
---|
429 | $objPage->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX; |
---|
430 | } else { |
---|
431 | $objPage->tpl_sale_limit[$product['product_id']] = $product['sale_limit']; |
---|
432 | } |
---|
433 | |
---|
434 | return $objPage; |
---|
435 | } |
---|
436 | |
---|
437 | //支払方法の取得 |
---|
438 | //payment_id 1:代金引換 2:銀行振り込み 3:現金書留 |
---|
439 | function lfGetPayment() { |
---|
440 | $objQuery = new SC_Query; |
---|
441 | $col = "payment_id, rule, payment_method"; |
---|
442 | $from = "dtb_payment"; |
---|
443 | $where = "del_flg = 0"; |
---|
444 | $order = "payment_id"; |
---|
445 | $objQuery->setorder($order); |
---|
446 | $arrRet = $objQuery->select($col, $from, $where); |
---|
447 | return $arrRet; |
---|
448 | } |
---|
449 | |
---|
450 | function lfconvertParam () { |
---|
451 | global $objPage; |
---|
452 | |
---|
453 | foreach ($objPage->arrForm as $key => $value) { |
---|
454 | if (preg_match('/^quantity[0-9]+/', $key)) { |
---|
455 | $objPage->arrForm[$key] |
---|
456 | = htmlspecialchars($objPage->arrForm[$key], ENT_QUOTES, CHAR_CODE); |
---|
457 | } |
---|
458 | } |
---|
459 | } |
---|
460 | } |
---|
461 | ?> |
---|