source: branches/comu-ver2/data/class/pages/admin/products/LC_Page_Admin_Products_ProductClass.php @ 17509

Revision 17509, 18.0 KB checked in by Seasoft, 16 years ago (diff)

パラメータ設定により、在庫無し商品を一覧に非表示しないように設定可能とする。
※ カテゴリ別おすすめ商品( SC_Utils::sfGetBestProducts() )はテスト方法が分からず、未テスト。
※ dtb_maker_count の更新は未対応。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
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$
33 */
34class LC_Page_Admin_Products_ProductClass extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/product_class.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_mainno = 'products';
49        $this->tpl_subno = 'product';
50        $this->tpl_subtitle = '商品登録(商品規格)';
51
52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrSRANK = $masterData->getMasterData("mtb_srank");
54        $this->arrDISP = $masterData->getMasterData("mtb_disp");
55        $this->arrCLASS = $masterData->getMasterData("mtb_class");
56        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
57        $this->tpl_onload = "";
58    }
59
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66        $objView = new SC_AdminView();
67        // 認証可否の判定
68        $objSess = new SC_Session();
69        SC_Utils_Ex::sfIsSuccess($objSess);
70
71        // 検索パラメータの引き継ぎ
72        foreach ($_POST as $key => $val) {
73            if (ereg("^search_", $key)) {
74                $this->arrSearchHidden[$key] = $val;
75            }
76        }
77
78        $this->tpl_product_id =
79            isset($_POST['product_id']) ? $_POST['product_id'] : "" ;
80
81        $this->tpl_pageno = isset($_POST['pageno']) ? $_POST['pageno'] : "";
82
83        if (!isset($_POST['mode'])) $_POST['mode'] = "";
84
85        switch($_POST['mode']) {
86        // 規格削除要求
87        case 'delete':
88            $objQuery = new SC_Query();
89            $objDb = new SC_Helper_DB_Ex();
90
91            $objQuery->setLimitOffset(1);
92            $where = "product_id = ? AND NOT (classcategory_id1 = 0 AND classcategory_id2 = 0)";
93            $objQuery->setOrder("rank1 DESC, rank2 DESC");
94            $arrRet = $objQuery->select("*", "vw_cross_products_class AS crs_prd", $where, array($_POST['product_id']));
95
96            if(count($arrRet) > 0) {
97
98                $sqlval['product_id'] = $arrRet[0]['product_id'];
99                $sqlval['classcategory_id1'] = '0';
100                $sqlval['classcategory_id2'] = '0';
101                $sqlval['product_code'] = $arrRet[0]['product_code'];
102                $sqlval['stock'] = $arrRet[0]['stock'];
103                $sqlval['price01'] = $arrRet[0]['price01'];
104                $sqlval['price02'] = $arrRet[0]['price02'];
105                $sqlval['creator_id'] = $_SESSION['member_id'];
106                $sqlval['create_date'] = "now()";
107                $sqlval['update_date'] = "now()";
108
109                $objQuery->begin();
110                $where = "product_id = ?";
111                $objQuery->delete("dtb_products_class", $where, array($_POST['product_id']));
112                $objQuery->insert("dtb_products_class", $sqlval);
113
114                $objQuery->commit();
115            }
116           
117            // 在庫無し商品の非表示対応
118            if (NOSTOCK_HIDDEN === true) {
119                // 件数カウントバッチ実行
120                $objDb->sfCategory_Count($objQuery);
121            }
122           
123            $this->lfProductClassPage();   // 規格登録ページ
124            break;
125
126        // 編集要求
127        case 'pre_edit':
128            $objQuery = new SC_Query();
129            $where = "product_id = ? AND NOT(classcategory_id1 = 0 AND classcategory_id2 = 0) ";
130            $ret = $objQuery->count("dtb_products_class", $where, array($_POST['product_id']));
131
132            if($ret > 0) {
133                // 規格組み合わせ一覧の取得(DBの値を優先する。)
134                $this->arrClassCat = $this->lfGetClassCatListEdit($_POST['product_id']);
135            }
136
137            $this->lfProductClassPage();   // 規格登録ページ
138            break;
139           
140        // 規格組み合わせ表示
141        case 'disp':
142            $this->arrForm['select_class_id1'] = $_POST['select_class_id1'];
143            $this->arrForm['select_class_id2'] = $_POST['select_class_id2'];
144
145            $this->arrErr = $this->lfClassError();
146            if (count($this->arrErr) == 0) {
147                // 規格組み合わせ一覧の取得
148                $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['select_class_id1'], $_POST['select_class_id2']);
149            }
150
151            $this->lfProductClassPage();   // 規格登録ページ
152            break;
153           
154        // 規格登録要求
155        case 'edit':
156            // 入力値の変換
157            $this->arrForm = $this->lfConvertParam($_POST);
158            // エラーチェック
159            $this->arrErr = $this->lfProductClassError($this->arrForm);
160
161            if(count($this->arrErr) == 0) {
162                // 確認ページ設定
163                $this->tpl_mainpage = 'products/product_class_confirm.tpl';
164                $this->lfProductConfirmPage(); // 確認ページ表示
165            } else {
166                // 規格組み合わせ一覧の取得
167                $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false);
168                $this->lfProductClassPage();   // 規格登録ページ
169            }
170            break;
171           
172        // 確認ページからの戻り
173        case 'confirm_return':
174            // フォームパラメータの引き継ぎ
175            $this->arrForm = $_POST;
176            // 規格の選択情報は引き継がない。
177            $this->arrForm['select_class_id1'] = "";
178            $this->arrForm['select_class_id2'] = "";
179            // 規格組み合わせ一覧の取得(デフォルト値は出力しない)
180            $this->arrClassCat = $this->lfGetClassCatListDisp($_POST['class_id1'], $_POST['class_id2'], false);
181            $this->lfProductClassPage();   // 規格登録ページ
182            break;
183           
184        case 'complete':
185            // 完了ページ設定
186            $this->tpl_mainpage = 'products/product_class_complete.tpl';
187            // 商品規格の登録
188            $this->lfInsertProductClass($_POST, $_POST['product_id']);
189            break;
190           
191        default:
192            $this->lfProductClassPage();   // 規格登録ページ
193            break;
194        }
195
196        $objView->assignobj($this);
197        $objView->display(MAIN_FRAME);
198    }
199
200    /**
201     * デストラクタ.
202     *
203     * @return void
204     */
205    function destroy() {
206        parent::destroy();
207    }
208
209    /* 規格登録ページ表示用 */
210    function lfProductClassPage() {
211        $objDb = new SC_Helper_DB_Ex();
212
213        $this->arrHidden = $_POST;
214        $this->arrHidden['select_class_id1'] = "";
215        $this->arrHidden['select_class_id2'] = "";
216        $arrClass = $objDb->sfGetIDValueList("dtb_class", 'class_id', 'name');
217
218        // 規格分類が登録されていない規格は表示しないようにする。
219        $arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount();
220
221        foreach($arrClass as $key => $val) {
222            if($arrClassCatCount[$key] > 0) {
223                $this->arrClass[$key] = $arrClass[$key];
224            }
225        }
226
227        // 商品名を取得
228        $objQuery = new SC_Query();
229        $product_name = $objQuery->getOne("SELECT name FROM dtb_products WHERE product_id = ?", array($_POST['product_id']));
230        $this->arrForm['product_name'] = $product_name;
231    }
232
233    function lfSetDefaultClassCat($objQuery, $product_id, $max) {
234
235        // デフォルト値の読込
236        $col = "product_code, price01, price02, stock, stock_unlimited";
237        $arrRet = $objQuery->select($col, "dtb_products_class", "product_id = ? AND classcategory_id1 = 0 AND classcategory_id2 = 0", array($product_id));;
238
239        if(count($arrRet) > 0) {
240            $no = 1;
241            for($cnt = 0; $cnt < $max; $cnt++) {
242                $this->arrForm["product_code:".$no] = $arrRet[0]['product_code'];
243                $this->arrForm['stock:'.$no] = $arrRet[0]['stock'];
244                $this->arrForm['price01:'.$no] = $arrRet[0]['price01'];
245                $this->arrForm['price02:'.$no] = $arrRet[0]['price02'];
246                $this->arrForm['stock_unlimited:'.$no] = $arrRet[0]['stock_unlimited'];
247                $no++;
248            }
249        }
250    }
251
252    /* 規格組み合わせ一覧の取得 */
253    function lfGetClassCatListDisp($class_id1, $class_id2, $default = true) {
254        $objQuery = new SC_Query();
255
256        if($class_id2 != "") {
257            // 規格1と規格2
258            $sql = "SELECT * ";
259            $sql.= "FROM vw_cross_class AS crs_cls ";
260            $sql.= "WHERE class_id1 = ? AND class_id2 = ? ORDER BY rank1 DESC, rank2 DESC;";
261            $arrRet = $objQuery->getall($sql, array($class_id1, $class_id2));
262        } else {
263            // 規格1のみ
264            $sql = "SELECT * ";
265            $sql.= "FROM vw_cross_class AS crs_cls ";
266            $sql.= "WHERE class_id1 = ? AND class_id2 = 0 ORDER BY rank1 DESC;";
267            $arrRet = $objQuery->getall($sql, array($class_id1));
268
269        }
270
271        $max = count($arrRet);
272
273        if($default) {
274            // デフォルト値を設定
275            $this->lfSetDefaultClassCat($objQuery, $_POST['product_id'], $max);
276        }
277
278        $this->arrForm["class_id1"] = $arrRet[0]['class_id1'];
279        $this->arrForm["class_id2"] = $arrRet[0]['class_id2'];
280        $this->tpl_onload.= "fnCheckAllStockLimit('$max', '" . DISABLED_RGB . "');";
281
282        return $arrRet;
283    }
284
285    /* 規格組み合わせ一覧の取得(編集画面) */
286    function lfGetClassCatListEdit($product_id) {
287        // 既存編集の場合
288        $objQuery = new SC_Query();
289
290        $col = "class_id1, class_id2, name1, name2, rank1, rank2, ";
291        $col.= "product_class_id, product_id, T1_classcategory_id AS classcategory_id1, T2_classcategory_id AS classcategory_id2, ";
292        $col.= "product_code, stock, stock_unlimited, sale_limit, price01, price02, status";
293
294        $sql = "SELECT $col FROM ";
295        $sql.= "( ";
296        $sql.= "SELECT T1.class_id AS class_id1, T2.class_id AS class_id2, T1.classcategory_id AS T1_classcategory_id, T2.classcategory_id AS T2_classcategory_id, T1.name AS name1, T2.name AS name2, T1.rank AS rank1, T2.rank AS rank2 ";
297        $sql.= "FROM dtb_classcategory AS T1, dtb_classcategory AS T2 ";
298        $sql.= "WHERE T1.class_id IN (SELECT class_id1 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2) AND T2.class_id IN (SELECT class_id2 FROM vw_cross_products_class AS crs_prd WHERE product_id = ? GROUP BY class_id1, class_id2)";
299        $sql.= ") AS T1 ";
300
301        $sql.= "LEFT JOIN (SELECT * FROM dtb_products_class WHERE product_id = ?) AS T3 ";
302        $sql.= "ON T1_classcategory_id = T3.classcategory_id1 AND T2_classcategory_id = T3.classcategory_id2 ";
303        $sql.= "ORDER BY rank1 DESC, rank2 DESC";
304
305        $arrList =  $objQuery->getAll($sql, array($product_id, $product_id, $product_id));
306
307        $this->arrForm["class_id1"] = $arrList[0]['class_id1'];
308        $this->arrForm["class_id2"] = $arrList[0]['class_id2'];
309
310        $max = count($arrList);
311
312        // デフォルト値を設定
313        $this->lfSetDefaultClassCat($objQuery, $product_id, $max);
314
315        $no = 1;
316
317        for($cnt = 0; $cnt < $max; $cnt++) {
318            $this->arrForm["classcategory_id1:".$no] = $arrList[$cnt]['classcategory_id1'];
319            $this->arrForm["classcategory_id2:".$no] = $arrList[$cnt]['classcategory_id2'];
320            if($arrList[$cnt]['product_id'] != "") {
321                $this->arrForm["product_code:".$no] = $arrList[$cnt]['product_code'];
322                $this->arrForm['stock:'.$no] = $arrList[$cnt]['stock'];
323                $this->arrForm['stock_unlimited:'.$no] = $arrList[$cnt]['stock_unlimited'];
324                $this->arrForm['price01:'.$no] = $arrList[$cnt]['price01'];
325                $this->arrForm['price02:'.$no] = $arrList[$cnt]['price02'];
326                // JavaScript初期化用文字列
327                $line.= "'check:".$no."',";
328            }
329            $no++;
330        }
331
332        $line = ereg_replace(",$", "", $line);
333        $this->tpl_javascript = "list = new Array($line);";
334        $color = DISABLED_RGB;
335        $this->tpl_onload.= "fnListCheck(list); fnCheckAllStockLimit('$max', '$color');";
336
337        return $arrList;
338    }
339
340    /* 規格の登録 */
341    function lfInsertProductClass($arrList, $product_id) {
342        $objQuery = new SC_Query();
343        $objDb = new SC_Helper_DB_Ex();
344
345        $objQuery->begin();
346
347        // 既存規格の削除
348        $where = "product_id = ?";
349        $objQuery->delete("dtb_products_class", $where, array($product_id));
350
351        $cnt = 1;
352        // すべての規格を登録する。
353        while($arrList["classcategory_id1:".$cnt] != "") {
354            if($arrList["check:".$cnt] == 1) {
355                $sqlval['product_id'] = $product_id;
356                $sqlval['classcategory_id1'] = $arrList["classcategory_id1:".$cnt];
357                $sqlval['classcategory_id2'] = $arrList["classcategory_id2:".$cnt];
358                $sqlval['product_code'] = $arrList["product_code:".$cnt];
359                $sqlval['stock'] = $arrList["stock:".$cnt];
360                $sqlval['stock_unlimited'] = $arrList["stock_unlimited:".$cnt];
361                $sqlval['price01'] = $arrList['price01:'.$cnt];
362                $sqlval['price02'] = $arrList['price02:'.$cnt];
363                $sqlval['creator_id'] = $_SESSION['member_id'];
364                $sqlval['create_date'] = "now()";
365                $sqlval['update_date'] = "now()";
366                // INSERTの実行
367                $objQuery->insert("dtb_products_class", $sqlval);
368            }
369            $cnt++;
370        }
371       
372        // 件数カウントバッチ実行
373        $objDb->sfCategory_Count($objQuery);
374       
375        $objQuery->commit();
376    }
377
378    // 規格選択エラーチェック
379    function lfClassError() {
380        $objErr = new SC_CheckError();
381        $objErr->doFunc(array("規格1", "select_class_id1"), array("EXIST_CHECK"));
382        $objErr->doFunc(array("規格", "select_class_id1", "select_class_id2"), array("TOP_EXIST_CHECK"));
383        $objErr->doFunc(array("規格1", "規格2", "select_class_id1", "select_class_id2"), array("DIFFERENT_CHECK"));
384        return $objErr->arrErr;
385    }
386
387    /* 取得文字列の変換 */
388    function lfConvertParam($array) {
389        /*
390         *  文字列の変換
391         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
392         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
393         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
394         *  n :  「全角」数字を「半角(ハンカク)」に変換
395         */
396
397        $no = 1; // FIXME 未定義変数の修正
398        while($array["classcategory_id1:".$no] != "") {
399            $arrConvList["product_code:".$no] = "KVa";
400            $arrConvList["price01:".$no] = "n";
401            $arrConvList["price02:".$no] = "n";
402            $arrConvList["stock:".$no] = "n";
403            $no++;
404        }
405
406        // 文字変換
407        foreach ($arrConvList as $key => $val) {
408            // POSTされてきた値のみ変換する。
409            if(isset($array[$key])) {
410                $array[$key] = mb_convert_kana($array[$key] ,$val);
411            }
412        }
413        return $array;
414    }
415
416    // 商品規格エラーチェック
417    function lfProductClassError($array) {
418        $objErr = new SC_CheckError($array);
419        $no = 1; // FIXME 未定義変数の修正
420        while($array["classcategory_id1:".$no] != "") {
421            if($array["check:".$no] == 1) {
422                $objErr->doFunc(array("商品コード", "product_code:".$no, STEXT_LEN), array("MAX_LENGTH_CHECK"));
423                $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01:".$no, PRICE_LEN), array("ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
424                $objErr->doFunc(array(SALE_PRICE_TITLE, "price02:".$no, PRICE_LEN), array("EXIST_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
425
426                if($array["stock_unlimited:".$no] != '1') {
427                    $objErr->doFunc(array("在庫数", "stock:".$no, AMOUNT_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
428                }
429            }
430            if(count($objErr->arrErr) > 0) {
431                $objErr->arrErr["error:".$no] = $objErr->arrErr["product_code:".$no];
432                $objErr->arrErr["error:".$no].= $objErr->arrErr["price01:".$no];
433                $objErr->arrErr["error:".$no].= $objErr->arrErr["price02:".$no];
434                $objErr->arrErr["error:".$no].= $objErr->arrErr["stock:".$no];
435            }
436            $no++;
437        }
438        return $objErr->arrErr;
439    }
440
441    /* 確認ページ表示用 */
442    function lfProductConfirmPage() {
443        $objDb = new SC_Helper_DB_Ex();
444        $this->arrForm['mode'] = 'complete';
445        $this->arrClass = $objDb->sfGetIDValueList("dtb_class", 'class_id', 'name');
446        $cnt = 0;
447        $check = 0;
448        $no = 1;
449        while($_POST["classcategory_id1:".$no] != "") {
450            if($_POST["check:".$no] != "") {
451                $check++;
452            }
453            $no++;
454            $cnt++;
455        }
456        $this->tpl_check = $check;
457        $this->tpl_count = $cnt;
458    }
459}
460?>
Note: See TracBrowser for help on using the repository browser.