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

Revision 18142, 28.8 KB checked in by ramrun, 15 years ago (diff)

商品一覧ページでcategory_id、商品詳細ページでproduct_idの正当性をチェック

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