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

Revision 18195, 29.2 KB checked in by ramrun, 15 years ago (diff)

r18187で商品一覧のページ送りをGETに変更したことによる表示件数・順序の処理変更

  • 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 (!defined('MOBILE_SITE') && !isset($_REQUEST['category_id']))
391            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
392        if ($category_id
393                && (!SC_Utils_Ex::sfIsInt($category_id)
394                || SC_Utils_Ex::sfIsZeroFilling($category_id)
395                || !$objDb->sfIsRecord('dtb_category', 'category_id', (array)$category_id, 'del_flg = 0')))
396            SC_Utils_Ex::sfDispSiteError(CATEGORY_NOT_FOUND);
397    }
398
399    /* カテゴリIDがルートかどうかの判定 */
400    function lfIsRootCategory($category_id) {
401        $objQuery = new SC_Query();
402        $level = $objQuery->get("dtb_category", "level", "category_id = ?", array($category_id));
403        if($level == 1) {
404            return true;
405        }
406        return false;
407    }
408
409    /* 商品一覧の表示 */
410    function lfDispProductsList($category_id, $name, $maker_id, $disp_num, $orderby) {
411
412        $objQuery = new SC_Query();
413        $objDb = new SC_Helper_DB_Ex();
414        $this->tpl_pageno = @$_GET['pageno'];
415        $arrval = array();
416        $arrval_order = array();
417        $arrval_category = array();
418       
419        // カテゴリからのWHERE文字列取得
420        if ( $category_id ) {
421            list($where_category, $arrval_category) = $objDb->sfGetCatWhere($category_id);
422        }
423       
424        // ▼対象商品IDの抽出
425        // 商品検索条件の作成(未削除、表示)
426        $where = "del_flg = 0 AND status = 1 ";
427       
428        // 在庫無し商品の非表示
429        if (NOSTOCK_HIDDEN === true) {
430            $where .= ' AND (stock_max >= 1 OR stock_unlimited_max = 1)';
431        }
432       
433        if (strlen($where_category) >= 1) {
434            $where.= " AND $where_category";
435            $arrval = array_merge($arrval, $arrval_category);
436        }
437
438        // 商品名をwhere文に
439        $name = ereg_replace(",", "", $name);// XXX
440        // 全角スペースを半角スペースに変換
441        $name = str_replace(' ', ' ', $name);
442        // スペースでキーワードを分割
443        $names = preg_split("/ +/", $name);
444        // 分割したキーワードを一つずつwhere文に追加
445        foreach ($names as $val) {
446            if ( strlen($val) > 0 ){
447                $where .= " AND ( name ILIKE ? OR comment3 ILIKE ?) ";
448                $ret = SC_Utils_Ex::sfManualEscape($val);
449                $arrval[] = "%$ret%";
450                $arrval[] = "%$ret%";
451            }
452        }
453
454        // メーカーらのWHERE文字列取得
455        if ( $maker_id ) {
456            $where .= " AND maker_id = ? ";
457            $arrval[] = $maker_id;
458        }
459       
460        $arrProduct_id = $objQuery->getCol('vw_products_allclass AS allcls', 'DISTINCT product_id', $where, $arrval);
461        // ▲対象商品IDの抽出
462       
463        // 行数の取得
464        $linemax = count($arrProduct_id);
465
466        $this->tpl_linemax = $linemax;   // 何件が該当しました。表示用
467
468        // ページ送りの取得
469        $this->objNavi = new SC_PageNavi($this->tpl_pageno, $linemax, $disp_num, "fnNaviPage", NAVI_PMAX);
470        $strnavi = $this->objNavi->strnavi;
471        $strnavi = preg_replace('/list\.php.*?\'([0-9]+)\'.*?\"/', 'list.php?category_id=' . $category_id . '&amp;pageno=$1"', $strnavi);
472 
473        // 表示文字列
474        $this->tpl_strnavi = empty($strnavi) ? "&nbsp;" : $strnavi;
475        $startno = $this->objNavi->start_row;                 // 開始行
476       
477        // ▼商品詳細取得
478        $col = <<< __EOS__
479             product_id
480            ,product_code_min
481            ,product_code_max
482            ,name
483            ,comment1
484            ,comment2
485            ,comment3
486            ,main_list_comment
487            ,main_image
488            ,main_list_image
489            ,price01_min
490            ,price01_max
491            ,price02_min
492            ,price02_max
493            ,stock_min
494            ,stock_max
495            ,stock_unlimited_min
496            ,stock_unlimited_max
497            ,point_rate
498            ,sale_limit
499            ,sale_unlimited
500            ,deliv_date_id
501            ,deliv_fee
502            ,status
503            ,product_flag
504            ,del_flg
505__EOS__;
506       
507        $from = "vw_products_allclass_detail AS alldtl";
508       
509        // WHERE 句
510        $where = '0=0';
511        if (is_array($arrProduct_id) && !empty($arrProduct_id)) {
512            $where .= ' AND product_id IN (' . implode(',', $arrProduct_id) . ')';
513        } else {
514            // 一致させない
515            $where .= ' AND 0<>0';
516        }
517       
518        //表示順序
519        switch($orderby) {
520
521            //販売価格順
522            case 'price':
523                $order = "price02_min, product_id";
524                break;
525
526            //新着順
527            case 'date':
528                $order = "create_date DESC, product_id";
529                break;
530
531            default:
532                if (strlen($where_category) >= 1) {
533                    $dtb_product_categories = "(SELECT * FROM dtb_product_categories WHERE $where_category)";
534                    $arrval_order = array_merge($arrval_category, $arrval_category);
535                } else {
536                    $dtb_product_categories = 'dtb_product_categories';
537                }
538                $order = <<< __EOS__
539                    (
540                        SELECT
541                             T3.rank
542                        FROM
543                            $dtb_product_categories T2
544                            JOIN dtb_category T3
545                                USING (category_id)
546                        WHERE T2.product_id = alldtl.product_id
547                        ORDER BY T3.rank DESC, T2.rank DESC
548                        LIMIT 1
549                    ) DESC
550                    ,(
551                        SELECT
552                            T2.rank
553                        FROM
554                            $dtb_product_categories T2
555                            JOIN dtb_category T3
556                                USING (category_id)
557                        WHERE T2.product_id = alldtl.product_id
558                        ORDER BY T3.rank DESC, T2.rank DESC
559                        LIMIT 1
560                    ) DESC
561                    ,product_id
562__EOS__;
563                break;
564        }
565       
566        // 取得範囲の指定(開始行番号、行数のセット)
567        $objQuery->setlimitoffset($disp_num, $startno);
568        // 表示順序
569        $objQuery->setorder($order);
570       
571        // 検索結果の取得
572        $this->arrProducts = $objQuery->select($col, $from, $where, $arrval_order);
573        // ▲商品詳細取得
574       
575        // 規格名一覧
576        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
577        // 規格分類名一覧
578        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
579        // 規格セレクトボックス設定
580        if($disp_num == 15) {
581            for($i = 0; $i < count($this->arrProducts); $i++) {
582                $this->lfMakeSelect($this->arrProducts[$i]['product_id'], $arrClassName, $arrClassCatName);
583                // 購入制限数を取得
584                $this->lfGetSaleLimit($this->arrProducts[$i]);
585            }
586        }
587    }
588
589    /* 規格セレクトボックスの作成 */
590    function lfMakeSelect($product_id, $arrClassName, $arrClassCatName) {
591
592        $classcat_find1 = false;
593        $classcat_find2 = false;
594        // 在庫ありの商品の有無
595        $stock_find = false;
596
597        // 商品規格情報の取得
598        $arrProductsClass = $this->lfGetProductsClass($product_id);
599
600        // 規格1クラス名の取得
601        $this->tpl_class_name1[$product_id] =
602            isset($arrClassName[$arrProductsClass[0]['class_id1']])
603            ? $arrClassName[$arrProductsClass[0]['class_id1']]
604            : "";
605
606        // 規格2クラス名の取得
607        $this->tpl_class_name2[$product_id] =
608            isset($arrClassName[$arrProductsClass[0]['class_id2']])
609            ? $arrClassName[$arrProductsClass[0]['class_id2']]
610            : "";
611
612        // すべての組み合わせ数
613        $count = count($arrProductsClass);
614
615        $classcat_id1 = "";
616
617        $arrSele = array();
618        $arrList = array();
619
620        $list_id = 0;
621        $arrList[0] = "\tlist". $product_id. "_0 = new Array('選択してください'";
622        $arrVal[0] = "\tval". $product_id. "_0 = new Array(''";
623
624        for ($i = 0; $i < $count; $i++) {
625            // 在庫のチェック
626            if($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') {
627                continue;
628            }
629
630            $stock_find = true;
631
632            // 規格1のセレクトボックス用
633            if($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']){
634                $arrList[$list_id].=");\n";
635                $arrVal[$list_id].=");\n";
636                $classcat_id1 = $arrProductsClass[$i]['classcategory_id1'];
637                $arrSele[$classcat_id1] = $arrClassCatName[$classcat_id1];
638                $list_id++;
639
640                $arrList[$list_id] = "";
641                $arrVal[$list_id] = "";
642            }
643
644            // 規格2のセレクトボックス用
645            $classcat_id2 = $arrProductsClass[$i]['classcategory_id2'];
646
647            // セレクトボックス表示値
648            if($arrList[$list_id] == "") {
649                $arrList[$list_id] = "\tlist". $product_id. "_". $list_id. " = new Array('選択してください', '". $arrClassCatName[$classcat_id2]. "'";
650            } else {
651                $arrList[$list_id].= ", '".$arrClassCatName[$classcat_id2]."'";
652            }
653
654            // セレクトボックスPOST値
655            if($arrVal[$list_id] == "") {
656                $arrVal[$list_id] = "\tval". $product_id. "_". $list_id. " = new Array('', '". $classcat_id2. "'";
657            } else {
658                $arrVal[$list_id].= ", '".$classcat_id2."'";
659            }
660        }
661
662        $arrList[$list_id].=");\n";
663        $arrVal[$list_id].=");\n";
664
665        // 規格1
666        $this->arrClassCat1[$product_id] = $arrSele;
667
668        $lists = "\tlists".$product_id. " = new Array(";
669        $no = 0;
670        foreach($arrList as $val) {
671            $this->tpl_javascript.= $val;
672            if ($no != 0) {
673                $lists.= ",list". $product_id. "_". $no;
674            } else {
675                $lists.= "list". $product_id. "_". $no;
676            }
677            $no++;
678        }
679        $this->tpl_javascript.= $lists.");\n";
680
681        $vals = "\tvals".$product_id. " = new Array(";
682        $no = 0;
683        foreach($arrVal as $val) {
684            $this->tpl_javascript.= $val;
685            if ($no != 0) {
686                $vals.= ",val". $product_id. "_". $no;
687            } else {
688                $vals.= "val". $product_id. "_". $no;
689            }
690            $no++;
691        }
692        $this->tpl_javascript.= $vals.");\n";
693
694        // 選択されている規格2ID
695        $classcategory_id = "classcategory_id". $product_id;
696
697        $classcategory_id_2 = $classcategory_id . "_2";
698        if (!isset($classcategory_id_2)) $classcategory_id_2 = "";
699        if (!isset($_POST[$classcategory_id_2]) || !is_numeric($_POST[$classcategory_id_2])) $_POST[$classcategory_id_2] = "";
700
701        $this->tpl_onload .= "lnSetSelect('" . $classcategory_id ."_1', "
702            . "'" . $classcategory_id_2 . "',"
703            . "'" . $product_id . "',"
704            . "'" . $_POST[$classcategory_id_2] ."'); ";
705
706        // 規格1が設定されている
707        if($arrProductsClass[0]['classcategory_id1'] != '0') {
708            $classcat_find1 = true;
709        }
710
711        // 規格2が設定されている
712        if($arrProductsClass[0]['classcategory_id2'] != '0') {
713            $classcat_find2 = true;
714        }
715
716        $this->tpl_classcat_find1[$product_id] = $classcat_find1;
717        $this->tpl_classcat_find2[$product_id] = $classcat_find2;
718        $this->tpl_stock_find[$product_id] = $stock_find;
719    }
720
721    /* 商品規格情報の取得 */
722    function lfGetProductsClass($product_id) {
723        $arrRet = array();
724        if(SC_Utils_Ex::sfIsInt($product_id)) {
725            // 商品規格取得
726            $objQuery = new SC_Query();
727            $col = "product_class_id, classcategory_id1, classcategory_id2, class_id1, class_id2, stock, stock_unlimited";
728            $table = "vw_product_class AS prdcls";
729            $where = "product_id = ?";
730            $objQuery->setorder("rank1 DESC, rank2 DESC");
731            $arrRet = $objQuery->select($col, $table, $where, array($product_id));
732        }
733        return $arrRet;
734    }
735
736    /* 入力内容のチェック */
737    function lfCheckError($id) {
738
739        // 入力データを渡す。
740        $objErr = new SC_CheckError();
741
742        $classcategory_id1 = "classcategory_id". $id. "_1";
743        $classcategory_id2 = "classcategory_id". $id. "_2";
744        $quantity = "quantity". $id;
745        // 複数項目チェック
746        if ($this->tpl_classcat_find1[$id]) {
747            $objErr->doFunc(array("規格1", $classcategory_id1, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
748        }
749        if ($this->tpl_classcat_find2[$id]) {
750            $objErr->doFunc(array("規格2", $classcategory_id2, INT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
751        }
752        $objErr->doFunc(array("数量", $quantity, INT_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
753
754        return $objErr->arrErr;
755    }
756
757    // 購入制限数の設定
758    function lfGetSaleLimit($product) {
759        //在庫が無限または購入制限値が設定値より大きい場合
760        if($product['sale_unlimited'] == 1 || $product['sale_limit'] > SALE_LIMIT_MAX) {
761            $this->tpl_sale_limit[$product['product_id']] = SALE_LIMIT_MAX;
762        } else {
763            $this->tpl_sale_limit[$product['product_id']] = $product['sale_limit'];
764        }
765    }
766
767    //支払方法の取得
768    //payment_id    1:代金引換 2:銀行振り込み 3:現金書留
769    function lfGetPayment() {
770        $objQuery = new SC_Query;
771        $col = "payment_id, rule, payment_method";
772        $from = "dtb_payment";
773        $where = "del_flg = 0";
774        $order = "payment_id";
775        $objQuery->setorder($order);
776        $arrRet = $objQuery->select($col, $from, $where);
777        return $arrRet;
778    }
779
780    function lfconvertParam () {
781        foreach ($this->arrForm as $key => $value) {
782            if (preg_match('/^quantity[0-9]+/', $key)) {
783                 $this->arrForm[$key]
784                    = htmlspecialchars($this->arrForm[$key], ENT_QUOTES, CHAR_CODE);
785            }
786        }
787    }
788}
789?>
Note: See TracBrowser for help on using the repository browser.