source: branches/comu-ver2/data/class/pages/products/LC_Page_Products_List.php @ 18239

Revision 18239, 29.0 KB checked in by ramrun, 15 years ago (diff)

r18142 修正 list.php(パラメータ無し)で商品一覧を表示させる
 http://xoops.ec-cube.net/modules/newbb/viewtopic.php?viewmode=flat&topic_id=4364&forum=8

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