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:LC_Page_Products_List.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
17 | */ |
---|
18 | class LC_Page_Products_List extends LC_Page { |
---|
19 | |
---|
20 | // {{{ properties |
---|
21 | |
---|
22 | /** テンプレートクラス名1 */ |
---|
23 | var $tpl_class_name1; |
---|
24 | |
---|
25 | /** テンプレートクラス名2 */ |
---|
26 | var $tpl_class_name2; |
---|
27 | |
---|
28 | /** JavaScript テンプレート */ |
---|
29 | var $tpl_javascript; |
---|
30 | |
---|
31 | // }}} |
---|
32 | // {{{ functions |
---|
33 | |
---|
34 | /** |
---|
35 | * Page を初期化する. |
---|
36 | * |
---|
37 | * @return void |
---|
38 | */ |
---|
39 | function init() { |
---|
40 | parent::init(); |
---|
41 | |
---|
42 | $masterData = new SC_DB_MasterData_Ex(); |
---|
43 | $this->arrSTATUS = $masterData->getMasterData("mtb_status"); |
---|
44 | $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image"); |
---|
45 | $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date"); |
---|
46 | $this->arrPRODUCTLISTMAX = $masterData->getMasterData("mtb_product_list_max"); |
---|
47 | |
---|
48 | $this->tpl_class_name1 = array(); |
---|
49 | $this->tpl_class_name2 = array(); |
---|
50 | $this->allowClientCache(); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Page のプロセス. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function process() { |
---|
59 | $conn = new SC_DBConn(); |
---|
60 | $objDb = new SC_Helper_DB_Ex(); |
---|
61 | |
---|
62 | //表示件数の選択 |
---|
63 | if(isset($_POST['disp_number']) |
---|
64 | && SC_Utils_Ex::sfIsInt($_POST['disp_number'])) { |
---|
65 | $this->disp_number = $_POST['disp_number']; |
---|
66 | } else { |
---|
67 | //最小表示件数を選択 |
---|
68 | $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX)); |
---|
69 | } |
---|
70 | |
---|
71 | //表示順序の保存 |
---|
72 | $this->orderby = isset($_POST['orderby']) ? $_POST['orderby'] : ""; |
---|
73 | |
---|
74 | // GETのカテゴリIDを元に正しいカテゴリIDを取得する。 |
---|
75 | $arrCategory_id = $objDb->sfGetCategoryId("", $_GET['category_id']); |
---|
76 | |
---|
77 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
---|
78 | if (!isset($_GET['name'])) $_GET['name'] = ""; |
---|
79 | if (!isset($_POST['orderby'])) $_POST['orderby'] = ""; |
---|
80 | if (empty($arrCategory_id)) $arrCategory_id = array(""); |
---|
81 | |
---|
82 | // タイトル編集 |
---|
83 | $tpl_subtitle = ""; |
---|
84 | if ($_GET['mode'] == 'search') { |
---|
85 | $tpl_subtitle = "検索結果"; |
---|
86 | } elseif (empty($arrCategory_id)) { |
---|
87 | $tpl_subtitle = "全商品"; |
---|
88 | } else { |
---|
89 | $arrFirstCat = $objDb->sfGetFirstCat($arrCategory_id[0]); |
---|
90 | $tpl_subtitle = $arrFirstCat['name']; |
---|
91 | } |
---|
92 | |
---|
93 | $objQuery = new SC_Query(); |
---|
94 | $count = $objQuery->count("dtb_best_products", "category_id = ?", $arrCategory_id); |
---|
95 | |
---|
96 | // 以下の条件でBEST商品を表示する |
---|
97 | // ・BEST最大数の商品が登録されている。 |
---|
98 | // ・カテゴリIDがルートIDである。 |
---|
99 | // ・検索モードでない。 |
---|
100 | if(($count >= BEST_MIN) && $this->lfIsRootCategory($arrCategory_id[0]) && ($_GET['mode'] != 'search') ) { |
---|
101 | // 商品TOPの表示処理 |
---|
102 | $this->arrBestItems = SC_Utils_Ex::sfGetBestProducts($conn, $arrCategory_id[0]); |
---|
103 | $this->BEST_ROOP_MAX = ceil((BEST_MAX-1)/2); |
---|
104 | } else { |
---|
105 | if ($_GET['mode'] == 'search' && strlen($_GET['category_id']) == 0 ){ |
---|
106 | // 検索時にcategory_idがGETに存在しない場合は、仮に埋めたIDを空白に戻す |
---|
107 | $arrCategory_id = array(0); |
---|
108 | } |
---|
109 | |
---|
110 | // 商品一覧の表示処理 |
---|
111 | $this->lfDispProductsList($arrCategory_id[0], $_GET['name'], $this->disp_number, $_POST['orderby']); |
---|
112 | |
---|
113 | // 検索条件を画面に表示 |
---|
114 | // カテゴリー検索条件 |
---|
115 | if (strlen($_GET['category_id']) == 0) { |
---|
116 | $arrSearch['category'] = "指定なし"; |
---|
117 | }else{ |
---|
118 | $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?", $arrCategory_id); |
---|
119 | $arrSearch['category'] = $arrCat; |
---|
120 | } |
---|
121 | |
---|
122 | // 商品名検索条件 |
---|
123 | if ($_GET['name'] === "") { |
---|
124 | $arrSearch['name'] = "指定なし"; |
---|
125 | }else{ |
---|
126 | $arrSearch['name'] = $_GET['name']; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | // レイアウトデザインを取得 |
---|
131 | $layout = new SC_Helper_PageLayout_Ex(); |
---|
132 | $layout->sfGetPageLayout($this, false, "products/list.php"); |
---|
133 | |
---|
134 | if(isset($_POST['mode']) && $_POST['mode'] == "cart" |
---|
135 | && $_POST['product_id'] != "") { |
---|
136 | |
---|
137 | // 値の正当性チェック |
---|
138 | if(!SC_Utils_Ex::sfIsInt($_POST['product_id']) || !$objDb->sfIsRecord("dtb_products", "product_id", $_POST['product_id'], "del_flg = 0 AND status = 1")) { |
---|
139 | SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); |
---|
140 | } else { |
---|
141 | // 入力値の変換 |
---|
142 | $this->arrErr = $this->lfCheckError($_POST['product_id']); |
---|
143 | if(count($this->arrErr) == 0) { |
---|
144 | $objCartSess = new SC_CartSession(); |
---|
145 | $classcategory_id = "classcategory_id". $_POST['product_id']; |
---|
146 | $classcategory_id1 = $_POST[$classcategory_id. '_1']; |
---|
147 | $classcategory_id2 = $_POST[$classcategory_id. '_2']; |
---|
148 | $quantity = "quantity". $_POST['product_id']; |
---|
149 | // 規格1が設定されていない場合 |
---|
150 | if(!$this->tpl_classcat_find1[$_POST['product_id']]) { |
---|
151 | $classcategory_id1 = '0'; |
---|
152 | } |
---|
153 | // 規格2が設定されていない場合 |
---|
154 | if(!$this->tpl_classcat_find2[$_POST['product_id']]) { |
---|
155 | $classcategory_id2 = '0'; |
---|
156 | } |
---|
157 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
---|
158 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]); |
---|
159 | $this->sendRedirect($this->getLocation(URL_CART_TOP)); |
---|
160 | exit; |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | $this->tpl_subtitle = $tpl_subtitle; |
---|
166 | |
---|
167 | // 支払方法の取得 |
---|
168 | $this->arrPayment = $this->lfGetPayment(); |
---|
169 | // 入力情報を渡す |
---|
170 | $this->arrForm = $_POST; |
---|
171 | |
---|
172 | $this->lfConvertParam(); |
---|
173 | |
---|
174 | $this->category_id = $arrCategory_id[0]; |
---|
175 | $this->arrSearch = $arrSearch; |
---|
176 | |
---|
177 | SC_Utils_Ex::sfCustomDisplay($this); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * モバイルページを初期化する. |
---|
182 | * |
---|
183 | * @return void |
---|
184 | */ |
---|
185 | function mobileInit() { |
---|
186 | $this->init(); |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * Page のプロセス(モバイル). |
---|
191 | * |
---|
192 | * FIXME スパゲッティ... |
---|
193 | * |
---|
194 | * @return void |
---|
195 | */ |
---|
196 | function mobileProcess() { |
---|
197 | $conn = new SC_DBConn(); |
---|
198 | $objDb = new SC_Helper_DB_Ex(); |
---|
199 | |
---|
200 | //表示件数の選択 |
---|
201 | if(isset($_REQUEST['disp_number']) |
---|
202 | && SC_Utils_Ex::sfIsInt($_REQUEST['disp_number'])) { |
---|
203 | $this->disp_number = $_REQUEST['disp_number']; |
---|
204 | } else { |
---|
205 | //最小表示件数を選択 |
---|
206 | $this->disp_number = current(array_keys($this->arrPRODUCTLISTMAX)); |
---|
207 | } |
---|
208 | |
---|
209 | //表示順序の保存 |
---|
210 | $this->orderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : ""; |
---|
211 | |
---|
212 | // GETのカテゴリIDを元に正しいカテゴリIDを取得する。 |
---|
213 | $arrCategory_id = $objDb->sfGetCategoryId("", $_GET['category_id']); |
---|
214 | |
---|
215 | // タイトル編集 |
---|
216 | $tpl_subtitle = ""; |
---|
217 | $tpl_search_mode = false; |
---|
218 | |
---|
219 | if (!isset($_GET['mode'])) $_GET['mode'] = ""; |
---|
220 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
221 | if (!isset($_GET['name'])) $_GET['name'] = ""; |
---|
222 | if (!isset($_REQUEST['orderby'])) $_REQUEST['orderby'] = ""; |
---|
223 | |
---|
224 | if($_GET['mode'] == 'search'){ |
---|
225 | $tpl_subtitle = "検索結果"; |
---|
226 | $tpl_search_mode = true; |
---|
227 | }elseif (empty($arrCategory_id)) { |
---|
228 | $tpl_subtitle = "全商品"; |
---|
229 | }else{ |
---|
230 | $arrFirstCat = $objDb->sfGetFirstCat($arrCategory_id); |
---|
231 | $tpl_subtitle = $arrFirstCat['name']; |
---|
232 | } |
---|
233 | |
---|
234 | $objQuery = new SC_Query(); |
---|
235 | $count = $objQuery->count("dtb_best_products", "category_id = ?", $arrCategory_id); |
---|
236 | |
---|
237 | // 以下の条件でBEST商品を表示する |
---|
238 | // ・BEST最大数の商品が登録されている。 |
---|
239 | // ・カテゴリIDがルートIDである。 |
---|
240 | // ・検索モードでない。 |
---|
241 | if(($count >= BEST_MIN) && $this->lfIsRootCategory($arrCategory_id[0]) && ($_GET['mode'] != 'search') ) { |
---|
242 | // 商品TOPの表示処理 |
---|
243 | |
---|
244 | $this->arrBestItems = SC_Utils_Ex::sfGetBestProducts($conn, $arrCategory_id[0]); |
---|
245 | $this->BEST_ROOP_MAX = ceil((BEST_MAX-1)/2); |
---|
246 | } else { |
---|
247 | if ($_GET['mode'] == 'search' && strlen($_GET['category_id']) == 0 ){ |
---|
248 | // 検索時にcategory_idがGETに存在しない場合は、仮に埋めたIDを空白に戻す |
---|
249 | $arrCategory_id = array(""); |
---|
250 | } |
---|
251 | |
---|
252 | // 商品一覧の表示処理 |
---|
253 | $this->lfDispProductsList($arrCategory_id[0], $_GET['name'], $this->disp_number, $_REQUEST['orderby']); |
---|
254 | |
---|
255 | // 検索条件を画面に表示 |
---|
256 | // カテゴリー検索条件 |
---|
257 | if (strlen($_GET['category_id']) == 0) { |
---|
258 | $arrSearch['category'] = "指定なし"; |
---|
259 | }else{ |
---|
260 | $arrCat = $conn->getOne("SELECT category_name FROM dtb_category WHERE category_id = ?",array($category_id)); |
---|
261 | $arrSearch['category'] = $arrCat; |
---|
262 | } |
---|
263 | |
---|
264 | // 商品名検索条件 |
---|
265 | if ($_GET['name'] === "") { |
---|
266 | $arrSearch['name'] = "指定なし"; |
---|
267 | }else{ |
---|
268 | $arrSearch['name'] = $_GET['name']; |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | if($_POST['mode'] == "cart" && $_POST['product_id'] != "") { |
---|
273 | // 値の正当性チェック |
---|
274 | if(!SC_Utils_Ex::sfIsInt($_POST['product_id']) || !SC_Utils_Ex::sfIsRecord("dtb_products", "product_id", $_POST['product_id'], "del_flg = 0 AND status = 1")) { |
---|
275 | SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND, "", false, "", true); |
---|
276 | } else { |
---|
277 | // 入力値の変換 |
---|
278 | $this->arrErr = $this->lfCheckError($_POST['product_id']); |
---|
279 | if(count($this->arrErr) == 0) { |
---|
280 | $objCartSess = new SC_CartSession(); |
---|
281 | $classcategory_id = "classcategory_id". $_POST['product_id']; |
---|
282 | $classcategory_id1 = $_POST[$classcategory_id. '_1']; |
---|
283 | $classcategory_id2 = $_POST[$classcategory_id. '_2']; |
---|
284 | $quantity = "quantity". $_POST['product_id']; |
---|
285 | // 規格1が設定されていない場合 |
---|
286 | if(!$this->tpl_classcat_find1[$_POST['product_id']]) { |
---|
287 | $classcategory_id1 = '0'; |
---|
288 | } |
---|
289 | // 規格2が設定されていない場合 |
---|
290 | if(!$this->tpl_classcat_find2[$_POST['product_id']]) { |
---|
291 | $classcategory_id2 = '0'; |
---|
292 | } |
---|
293 | $objCartSess->setPrevURL($_SERVER['REQUEST_URI']); |
---|
294 | $objCartSess->addProduct(array($_POST['product_id'], $classcategory_id1, $classcategory_id2), $_POST[$quantity]); |
---|
295 | $this->sendRedirect(MOBILE_URL_CART_TOP, array(session_name() => session_id())); |
---|
296 | exit; |
---|
297 | } |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | |
---|
302 | // ページ送り機能用のURLを作成する。 |
---|
303 | $objURL = new Net_URL($_SERVER['PHP_SELF']); |
---|
304 | foreach ($_REQUEST as $key => $value) { |
---|
305 | if ($key == session_name() || $key == 'pageno') { |
---|
306 | continue; |
---|
307 | } |
---|
308 | $objURL->addQueryString($key, mb_convert_encoding($value, 'SJIS', CHAR_CODE)); |
---|
309 | } |
---|
310 | |
---|
311 | if ($this->objNavi->now_page > 1) { |
---|
312 | $objURL->addQueryString('pageno', $this->objNavi->now_page - 1); |
---|
313 | $this->tpl_previous_page = $objURL->path . '?' . $objURL->getQueryString(); |
---|
314 | } |
---|
315 | if ($this->objNavi->now_page < $this->objNavi->max_page) { |
---|
316 | $objURL->addQueryString('pageno', $this->objNavi->now_page + 1); |
---|
317 | $this->tpl_next_page = $objURL->path . '?' . $objURL->getQueryString(); |
---|
318 | } |
---|
319 | |
---|
320 | |
---|
321 | $this->tpl_subtitle = $tpl_subtitle; |
---|
322 | $this->tpl_search_mode = $tpl_search_mode; |
---|
323 | |
---|
324 | // 支払方法の取得 |
---|
325 | $this->arrPayment = $this->lfGetPayment(); |
---|
326 | // 入力情報を渡す |
---|
327 | $this->arrForm = $_POST; |
---|
328 | |
---|
329 | $this->category_id = $arrCategory_id[0]; |
---|
330 | $this->arrSearch = $arrSearch; |
---|
331 | $this->tpl_mainpage = MOBILE_TEMPLATE_DIR . "products/list.tpl"; |
---|
332 | SC_Utils_Ex::sfCustomDisplay($this, true); |
---|
333 | } |
---|
334 | |
---|
335 | /** |
---|
336 | * デストラクタ. |
---|
337 | * |
---|
338 | * @return void |
---|
339 | */ |
---|
340 | function destroy() { |
---|
341 | parent::destroy(); |
---|
342 | } |
---|
343 | |
---|
344 | /* カテゴリIDがルートかどうかの判定 */ |
---|
345 | function lfIsRootCategory($category_id) { |
---|
346 | $objQuery = new SC_Query(); |
---|
347 | $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id)); |
---|
348 | if($level == 1) { |
---|
349 | return true; |
---|
350 | } |
---|
351 | return false; |
---|
352 | } |
---|
353 | |
---|
354 | /* 商品一覧の表示 */ |
---|
355 | function lfDispProductsList($category_id, $name, $disp_num, $orderby) { |
---|
356 | |
---|
357 | $objQuery = new SC_Query(); |
---|
358 | $objDb = new SC_Helper_DB_Ex(); |
---|
359 | $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : ""; |
---|
360 | |
---|
361 | //表示順序 |
---|
362 | switch($orderby) { |
---|
363 | |
---|
364 | //価格順 |
---|
365 | case 'price': |
---|
366 | $distinct = "DISTINCT ON (price02_min, product_id)"; |
---|
367 | $col = $distinct . " *"; |
---|
368 | $from = "vw_products_allclass "; |
---|
369 | $order = "price02_min ASC, product_id ASC"; |
---|
370 | break; |
---|
371 | |
---|
372 | //新着順 |
---|
373 | case 'date': |
---|
374 | $distinct = "DISTINCT ON (create_date, product_id)"; |
---|
375 | $col = $distinct . " *"; |
---|
376 | $from = "vw_products_allclass "; |
---|
377 | $order = "create_date DESC, product_id ASC"; |
---|
378 | break; |
---|
379 | |
---|
380 | default: |
---|
381 | $col = "DISTINCT T1.product_id, product_code_min, product_code_max," |
---|
382 | . " price01_min, price01_max, price02_min, price02_max, " |
---|
383 | . " stock_min, stock_max, stock_unlimited_min, " |
---|
384 | . " stock_unlimited_max, del_flg, status, name, comment1, " |
---|
385 | . " comment2, comment3, main_list_comment, main_image, " |
---|
386 | . " main_list_image, product_flag, deliv_date_id, sale_limit," |
---|
387 | . " point_rate, sale_unlimited, create_date, deliv_fee, " |
---|
388 | . " T4.product_rank, T4.category_rank"; |
---|
389 | $from = "vw_products_allclass AS T1 " |
---|
390 | . " JOIN (" |
---|
391 | . " SELECT max(T3.rank) AS category_rank, " |
---|
392 | . " max(T2.rank) AS product_rank, " |
---|
393 | . " T2.product_id" |
---|
394 | . " FROM dtb_product_categories T2 " |
---|
395 | . " JOIN dtb_category T3 USING (category_id) " |
---|
396 | . " GROUP BY product_id) AS T4 USING (product_id)"; |
---|
397 | $order = "T4.category_rank DESC, T4.product_rank DESC"; |
---|
398 | break; |
---|
399 | } |
---|
400 | |
---|
401 | // 商品検索条件の作成(未削除、表示) |
---|
402 | $where = "del_flg = 0 AND status = 1 "; |
---|
403 | // カテゴリからのWHERE文字列取得 |
---|
404 | if ( $category_id ) { |
---|
405 | list($tmp_where, $arrval) = $objDb->sfGetCatWhere($category_id); |
---|
406 | if($tmp_where != "") { |
---|
407 | $where.= " AND $tmp_where"; |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | // 商品名をwhere文に |
---|
412 | $name = ereg_replace(",", "", $name); |
---|
413 | if ( strlen($name) > 0 ){ |
---|
414 | $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) "; |
---|
415 | $ret = SC_Utils_Ex::sfManualEscape($name); |
---|
416 | $arrval[] = "%$ret%"; |
---|
417 | $arrval[] = "%$ret%"; |
---|
418 | } |
---|
419 | |
---|
420 | if (empty($arrval)) { |
---|
421 | $arrval = array(); |
---|
422 | } |
---|
423 | |
---|
424 | // 行数の取得 |
---|
425 | $linemax = count($objQuery->getAll("SELECT DISTINCT product_id " |
---|
426 | . "FROM vw_products_allclass AS allcls " |
---|
427 | . (!empty($where) ? " WHERE " . $where |
---|
428 | : ""), $arrval)); |
---|
429 | |
---|
430 | $this->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
431 | |
---|
432 | // ページ送りの取得 |
---|
433 | $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $disp_num, "fnNaviPage", NAVI_PMAX); |
---|
434 | |
---|
435 | $strnavi = $this->objNavi->strnavi; |
---|
436 | $strnavi = str_replace('onclick="fnNaviPage', 'onclick="form1.mode.value=\''.'\'; fnNaviPage', $strnavi); |
---|
437 | // 表示文字列 |
---|
438 | $this->tpl_strnavi = empty($strnavi) ? " " : $strnavi; |
---|
439 | $startno = $this->objNavi->start_row; // 開始行 |
---|
440 | |
---|
441 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
442 | $objQuery->setlimitoffset($disp_num, $startno); |
---|
443 | // 表示順序 |
---|
444 | $objQuery->setorder($order); |
---|
445 | |
---|
446 | // 検索結果の取得 |
---|
447 | $this->arrProducts = $objQuery->select($col, $from, $where, $arrval); |
---|
448 | |
---|
449 | // 規格名一覧 |
---|
450 | $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
451 | // 規格分類名一覧 |
---|
452 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
453 | // 規格セレクトボックス設定 |
---|
454 | if($disp_num == 15) { |
---|
455 | for($i = 0; $i < count($this->arrProducts); $i++) { |
---|
456 | $this->lfMakeSelect($this->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName); |
---|
457 | // 購入制限数を取得 |
---|
458 | $this->lfGetSaleLimit($this->arrProducts[$i]); |
---|
459 | } |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | /* 規格セレクトボックスの作成 */ |
---|
464 | function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) { |
---|
465 | |
---|
466 | $classcat_find1 = false; |
---|
467 | $classcat_find2 = false; |
---|
468 | // 在庫ありの商品の有無 |
---|
469 | $stock_find = false; |
---|
470 | |
---|
471 | // 商品規格情報の取得 |
---|
472 | $arrProductsClass = $this->lfGetProductsClass($product_id); |
---|
473 | |
---|
474 | // 規格1クラス名の取得 |
---|
475 | $this->tpl_class_name1[$product_id] = |
---|
476 | isset($arrClassName[$arrProductsClass[0]['class_id1']]) |
---|
477 | ? $arrClassName[$arrProductsClass[0]['class_id1']] |
---|
478 | : ""; |
---|
479 | |
---|
480 | // 規格2クラス名の取得 |
---|
481 | $this->tpl_class_name2[$product_id] = |
---|
482 | isset($arrClassName[$arrProductsClass[0]['class_id2']]) |
---|
483 | ? $arrClassName[$arrProductsClass[0]['class_id2']] |
---|
484 | : ""; |
---|
485 | |
---|
486 | // すべての組み合わせ数 |
---|
487 | $count = count($arrProductsClass); |
---|
488 | |
---|
489 | $classcat_id1 = ""; |
---|
490 | |
---|
491 | $arrSele = array(); |
---|
492 | $arrList = array(); |
---|
493 | |
---|
494 | $list_id = 0; |
---|
495 | $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'"; |
---|
496 | $arrVal[0] = "\tval". $product_id. "_0 = new Array(''"; |
---|
497 | |
---|
498 | for ($i = 0; $i < $count; $i++) { |
---|
499 | // 在庫のチェック |
---|
500 | if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { |
---|
501 | continue; |
---|
502 | } |
---|
503 | |
---|
504 | $stock_find = true; |
---|
505 | |
---|
506 | // 規格1のセレクトボックス用 |
---|
507 | if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){ |
---|
508 | $arrList[$list_id].=");\n"; |
---|
509 | $arrVal[$list_id].=");\n"; |
---|
510 | $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; |
---|
511 | $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1]; |
---|
512 | $list_id++; |
---|
513 | |
---|
514 | $arrList[$list_id] = ""; |
---|
515 | $arrVal[$list_id] = ""; |
---|
516 | } |
---|
517 | |
---|
518 | // 規格2のセレクトボックス用 |
---|
519 | $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; |
---|
520 | |
---|
521 | // セレクトボックス表示値 |
---|
522 | if($arrList[$list_id] == "") { |
---|
523 | $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'"; |
---|
524 | } else { |
---|
525 | $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'"; |
---|
526 | } |
---|
527 | |
---|
528 | // セレクトボックスPOST値 |
---|
529 | if($arrVal[$list_id] == "") { |
---|
530 | $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'"; |
---|
531 | } else { |
---|
532 | $arrVal[$list_id].= ", '".$classcat_id2."'"; |
---|
533 | } |
---|
534 | } |
---|
535 | |
---|
536 | $arrList[$list_id].=");\n"; |
---|
537 | $arrVal[$list_id].=");\n"; |
---|
538 | |
---|
539 | // 規格1 |
---|
540 | $this->arrClassCat1[$product_id] = $arrSele; |
---|
541 | |
---|
542 | $lists = "\tlists".$product_id. " = new Array("; |
---|
543 | $no = 0; |
---|
544 | foreach($arrList as $val) { |
---|
545 | $this->tpl_javascript.= $val; |
---|
546 | if ($no != 0) { |
---|
547 | $lists.= ",list". $product_id. "_". $no; |
---|
548 | } else { |
---|
549 | $lists.= "list". $product_id. "_". $no; |
---|
550 | } |
---|
551 | $no++; |
---|
552 | } |
---|
553 | $this->tpl_javascript.= $lists.");\n"; |
---|
554 | |
---|
555 | $vals = "\tvals".$product_id. " = new Array("; |
---|
556 | $no = 0; |
---|
557 | foreach($arrVal as $val) { |
---|
558 | $this->tpl_javascript.= $val; |
---|
559 | if ($no != 0) { |
---|
560 | $vals.= ",val". $product_id. "_". $no; |
---|
561 | } else { |
---|
562 | $vals.= "val". $product_id. "_". $no; |
---|
563 | } |
---|
564 | $no++; |
---|
565 | } |
---|
566 | $this->tpl_javascript.= $vals.");\n"; |
---|
567 | |
---|
568 | // 選択されている規格2ID |
---|
569 | $classcategory_id = "classcategory_id". $product_id; |
---|
570 | |
---|
571 | $classcategory_id_2 = $classcategory_id . "_2"; |
---|
572 | if (!isset($$classcategory_id_2)) $$classcategory_id_2 = ""; |
---|
573 | if (!isset($_POST[$$classcategory_id_2])) $_POST[$$classcategory_id_2] = ""; |
---|
574 | |
---|
575 | $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', " |
---|
576 | . "'" . $$classcategory_id_2 . "'," |
---|
577 | . "'" . $product_id . "'," |
---|
578 | . "'" . $_POST[$$classcategory_id_2] ."'); "; |
---|
579 | |
---|
580 | // 規格1が設定されている |
---|
581 | if($arrProductsClass[0]['classcategory_id1'] != '0') { |
---|
582 | $classcat_find1 = true; |
---|
583 | } |
---|
584 | |
---|
585 | // 規格2が設定されている |
---|
586 | if($arrProductsClass[0]['classcategory_id2'] != '0') { |
---|
587 | $classcat_find2 = true; |
---|
588 | } |
---|
589 | |
---|
590 | $this->tpl_classcat_find1[$product_id] = $classcat_find1; |
---|
591 | $this->tpl_classcat_find2[$product_id] = $classcat_find2; |
---|
592 | $this->tpl_stock_find[$product_id] = $stock_find; |
---|
593 | } |
---|
594 | |
---|
595 | /* 商品規格情報の取得 */ |
---|
596 | function lfGetProductsClass($product_id) { |
---|
597 | $arrRet = array(); |
---|
598 | if(SC_Utils_Ex::sfIsInt($product_id)) { |
---|
599 | // 商品規格取得 |
---|
600 | $objQuery = new SC_Query(); |
---|
601 | $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited"; |
---|
602 | $table = "vw_product_class AS prdcls"; |
---|
603 | $where = "product_id = ?"; |
---|
604 | $objQuery->setorder("rank1 DESC, rank2 DESC"); |
---|
605 | $arrRet = $objQuery->select($col, $table, $where, array($product_id)); |
---|
606 | } |
---|
607 | return $arrRet; |
---|
608 | } |
---|
609 | |
---|
610 | /* 入力内容のチェック */ |
---|
611 | function lfCheckError($id) { |
---|
612 | |
---|
613 | // 入力データを渡す。 |
---|
614 | $objErr = new SC_CheckError(); |
---|
615 | |
---|
616 | $classcategory_id1 = "classcategory_id". $id. "_1"; |
---|
617 | $classcategory_id2 = "classcategory_id". $id. "_2"; |
---|
618 | $quantity = "quantity". $id; |
---|
619 | // 複数項目チェック |
---|
620 | if ($this->tpl_classcat_find1[$id]) { |
---|
621 | $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
622 | } |
---|
623 | if ($this->tpl_classcat_find2[$id]) { |
---|
624 | $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
625 | } |
---|
626 | $objErr->doFunc(array("個数", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
627 | |
---|
628 | return $objErr->arrErr; |
---|
629 | } |
---|
630 | |
---|
631 | // 購入制限数の設定 |
---|
632 | function lfGetSaleLimit($product) { |
---|
633 | //在庫が無限または購入制限値が設定値より大きい場合 |
---|
634 | if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) { |
---|
635 | $this->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX; |
---|
636 | } else { |
---|
637 | $this->tpl_sale_limit[$product['product_id']] = $product['sale_limit']; |
---|
638 | } |
---|
639 | } |
---|
640 | |
---|
641 | //支払方法の取得 |
---|
642 | //payment_id 1:代金引換 2:銀行振り込み 3:現金書留 |
---|
643 | function lfGetPayment() { |
---|
644 | $objQuery = new SC_Query; |
---|
645 | $col = "payment_id, rule, payment_method"; |
---|
646 | $from = "dtb_payment"; |
---|
647 | $where = "del_flg = 0"; |
---|
648 | $order = "payment_id"; |
---|
649 | $objQuery->setorder($order); |
---|
650 | $arrRet = $objQuery->select($col, $from, $where); |
---|
651 | return $arrRet; |
---|
652 | } |
---|
653 | |
---|
654 | function lfconvertParam () { |
---|
655 | foreach ($this->arrForm as $key => $value) { |
---|
656 | if (preg_match('/^quantity[0-9]+/', $key)) { |
---|
657 | $this->arrForm[$key] |
---|
658 | = htmlspecialchars($this->arrForm[$key], ENT_QUOTES, CHAR_CODE); |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | } |
---|
663 | ?> |
---|